@surrealdb/memory 1.0.0-alpha.10 → 1.0.0-alpha.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +128 -4
- package/dist/memory.cjs +411 -14
- package/dist/memory.d.ts +2015 -244
- package/dist/memory.mjs +408 -15
- package/package.json +1 -1
package/dist/memory.mjs
CHANGED
|
@@ -354,7 +354,7 @@ var Documents = class {
|
|
|
354
354
|
|
|
355
355
|
//#endregion
|
|
356
356
|
//#region src/components/entities.ts
|
|
357
|
-
/** Entity records, attributes, relations, and attribute history. */
|
|
357
|
+
/** Entity records, attributes, relations, name search, and attribute history. */
|
|
358
358
|
var Entities = class {
|
|
359
359
|
transport;
|
|
360
360
|
contextId;
|
|
@@ -365,6 +365,9 @@ var Entities = class {
|
|
|
365
365
|
get base() {
|
|
366
366
|
return `${getContextApiPrefix(this.contextId)}/entities`;
|
|
367
367
|
}
|
|
368
|
+
entityPath(entityType, name) {
|
|
369
|
+
return `${this.base}/${encodePathSegment(entityType)}/${encodePathSegment(name)}`;
|
|
370
|
+
}
|
|
368
371
|
/** Lists one page of entities, optionally filtered by type. */
|
|
369
372
|
async list(options) {
|
|
370
373
|
const query = {};
|
|
@@ -395,22 +398,253 @@ var Entities = class {
|
|
|
395
398
|
});
|
|
396
399
|
return page.page.totalSize ?? page.entities.length;
|
|
397
400
|
}
|
|
398
|
-
/**
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
401
|
+
/**
|
|
402
|
+
* Searches entities by name, best match first (`GET /entities/search`).
|
|
403
|
+
*
|
|
404
|
+
* Lexical and deterministic: no model and no vector index in the path, so
|
|
405
|
+
* an identical query returns identical rows in an identical order. An exact
|
|
406
|
+
* match on the normalised identity name scores `1.0` and everything else
|
|
407
|
+
* strictly below it, corpus-independently — a score means the same thing in
|
|
408
|
+
* a context of ten entities and one of ten million.
|
|
409
|
+
*
|
|
410
|
+
* Each match carries its own `factCount` and a `distinguisher` drawn from
|
|
411
|
+
* its highest-importance facts, so two same-named candidates can be told
|
|
412
|
+
* apart without a request per candidate.
|
|
413
|
+
*
|
|
414
|
+
* This is a ranked head, not a walk: it is bounded by `limit` and offers no
|
|
415
|
+
* cursor. Use {@link Entities.list} to enumerate the collection.
|
|
416
|
+
*/
|
|
417
|
+
async search(query, options) {
|
|
418
|
+
const params = { q: query };
|
|
419
|
+
if (options?.type !== void 0) params.type = options.type;
|
|
420
|
+
if (options?.limit !== void 0) params.limit = options.limit;
|
|
421
|
+
const body = await this.transport.requestJson("GET", `${this.base}/search`, { query: params });
|
|
422
|
+
return body.matches;
|
|
423
|
+
}
|
|
424
|
+
/**
|
|
425
|
+
* The entities worth starting from (`GET /entities/top`).
|
|
426
|
+
*
|
|
427
|
+
* `coverage` (the default) is most-known-about, the one ordering the entity
|
|
428
|
+
* listing cannot express. It is exact rather than approximated, and costs
|
|
429
|
+
* an aggregate pass per fact family: merging three separately-truncated
|
|
430
|
+
* top-lists would mis-rank an entity that leads on relations and trails on
|
|
431
|
+
* attributes. Prefer `importance` or `recency`, both index-served
|
|
432
|
+
* single-table reads, where the ranking need not be exact.
|
|
433
|
+
*
|
|
434
|
+
* A ranked head, like {@link Entities.search}: bounded, with no cursor.
|
|
435
|
+
*/
|
|
436
|
+
async top(options) {
|
|
437
|
+
const params = {};
|
|
438
|
+
if (options?.by !== void 0) params.by = options.by;
|
|
439
|
+
if (options?.type !== void 0) params.type = options.type;
|
|
440
|
+
if (options?.limit !== void 0) params.limit = options.limit;
|
|
441
|
+
const body = await this.transport.requestJson("GET", `${this.base}/top`, { query: params });
|
|
442
|
+
return body.entities;
|
|
443
|
+
}
|
|
444
|
+
/**
|
|
445
|
+
* Fetches a single entity with a bounded head of its attributes and
|
|
446
|
+
* relations, newest first.
|
|
447
|
+
*
|
|
448
|
+
* Both fact sections are bounded by `limit` and report whether they were
|
|
449
|
+
* cut in `truncated`. To read one in full, walk its own collection: the
|
|
450
|
+
* attributes through `/attributes?entity=`, and the relations through
|
|
451
|
+
* **both** `/relations?src=` and `/relations?dst=`, because the head
|
|
452
|
+
* carries edges in either direction and one filter alone reproduces half of
|
|
453
|
+
* it. All of them page by cursor in this same order, so the head is a
|
|
454
|
+
* genuine prefix of the walk.
|
|
455
|
+
*/
|
|
456
|
+
async get(entityType, name, options) {
|
|
457
|
+
const query = {};
|
|
458
|
+
if (options?.limit !== void 0) query.limit = options.limit;
|
|
459
|
+
addTemporalParams(query, options);
|
|
460
|
+
const body = await this.transport.requestJson("GET", this.entityPath(entityType, name), { query });
|
|
461
|
+
return body;
|
|
462
|
+
}
|
|
463
|
+
/**
|
|
464
|
+
* One hop out from an entity (`GET /entities/{type}/{name}/neighbourhood`).
|
|
465
|
+
*
|
|
466
|
+
* Each neighbour carries its own `factCount`, so a relation chip is
|
|
467
|
+
* navigable rather than decorative — without it a caller needs one request
|
|
468
|
+
* per chip. Paginated over the edge's own `(createdAt, id)`, never the fact
|
|
469
|
+
* count, which moves under ingest.
|
|
470
|
+
*
|
|
471
|
+
* `limit` is capped below the general list limit because each row costs
|
|
472
|
+
* three correlated counts.
|
|
473
|
+
*/
|
|
474
|
+
async neighbours(entityType, name, options) {
|
|
475
|
+
const query = {};
|
|
476
|
+
if (options?.minFacts !== void 0) query.minFacts = options.minFacts;
|
|
477
|
+
addPageParams(query, options);
|
|
478
|
+
const body = await this.transport.requestJson("GET", `${this.entityPath(entityType, name)}/neighbourhood`, { query });
|
|
479
|
+
return body;
|
|
480
|
+
}
|
|
481
|
+
/** Every neighbour of an entity, following cursors to exhaustion. */
|
|
482
|
+
async allNeighbours(entityType, name, options) {
|
|
483
|
+
return collectPages((cursor) => this.neighbours(entityType, name, {
|
|
484
|
+
minFacts: options?.minFacts,
|
|
485
|
+
limit: options?.limit,
|
|
486
|
+
cursor
|
|
487
|
+
}), "neighbours", options?.max);
|
|
488
|
+
}
|
|
489
|
+
/**
|
|
490
|
+
* One page of every key's supersession chain for an entity, newest first
|
|
491
|
+
* (`GET /entities/{type}/{name}/history`).
|
|
492
|
+
*
|
|
493
|
+
* Answers what changed about the subject. The per-key sibling,
|
|
494
|
+
* {@link Entities.history}, answers how one value changed, and this cannot
|
|
495
|
+
* be composed from it without a request per key. Superseded rows are
|
|
496
|
+
* included — the chain is the point.
|
|
497
|
+
*/
|
|
498
|
+
async changes(entityType, name, options) {
|
|
499
|
+
const query = {};
|
|
500
|
+
addPageParams(query, options);
|
|
501
|
+
const body = await this.transport.requestJson("GET", `${this.entityPath(entityType, name)}/history`, { query });
|
|
402
502
|
return body;
|
|
403
503
|
}
|
|
504
|
+
/**
|
|
505
|
+
* The subject's whole change history, following cursors to exhaustion.
|
|
506
|
+
*
|
|
507
|
+
* Unbounded by construction: an attribute revised on every sync has an
|
|
508
|
+
* unbounded chain. Pass `max` to stop the walk once that many rows are in
|
|
509
|
+
* hand.
|
|
510
|
+
*/
|
|
511
|
+
async allChanges(entityType, name, options) {
|
|
512
|
+
return collectPages((cursor) => this.changes(entityType, name, {
|
|
513
|
+
limit: options?.limit,
|
|
514
|
+
cursor
|
|
515
|
+
}), "history", options?.max);
|
|
516
|
+
}
|
|
404
517
|
/** Returns the supersession history for one attribute key. */
|
|
405
518
|
async history(entityType, name, key) {
|
|
406
|
-
const path = `${this.
|
|
519
|
+
const path = `${this.entityPath(entityType, name)}/history/${encodePathSegment(key)}`;
|
|
407
520
|
const body = await this.transport.requestJson("GET", path);
|
|
408
521
|
return body.history;
|
|
409
522
|
}
|
|
410
523
|
/** Soft-deletes an entity (sets valid-until). */
|
|
411
524
|
async delete(entityType, name) {
|
|
412
|
-
|
|
413
|
-
|
|
525
|
+
await this.transport.requestJson("DELETE", this.entityPath(entityType, name));
|
|
526
|
+
}
|
|
527
|
+
};
|
|
528
|
+
/** Copies the temporal filters a caller supplied into a query object. */
|
|
529
|
+
function addTemporalParams(query, options) {
|
|
530
|
+
if (options?.asOf !== void 0) query.asOf = options.asOf;
|
|
531
|
+
if (options?.atInstant !== void 0) query.atInstant = options.atInstant;
|
|
532
|
+
if (options?.validFrom !== void 0) query.validFrom = options.validFrom;
|
|
533
|
+
if (options?.validUntil !== void 0) query.validUntil = options.validUntil;
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
//#endregion
|
|
537
|
+
//#region src/components/facts.ts
|
|
538
|
+
/**
|
|
539
|
+
* The fact collections, in the order the bounded reads present them.
|
|
540
|
+
*
|
|
541
|
+
* Every surface that returns a bounded head of facts — `entities.get`, the
|
|
542
|
+
* `/inspect` entity ref, and each section of `client.lookup` — reports
|
|
543
|
+
* `truncated` and points here for the rest. These listings page by cursor in
|
|
544
|
+
* the same newest-first order, so a truncated head is a genuine prefix of the
|
|
545
|
+
* walk rather than a separate ranking.
|
|
546
|
+
*/
|
|
547
|
+
var Facts = class {
|
|
548
|
+
transport;
|
|
549
|
+
contextId;
|
|
550
|
+
constructor(transport, contextId) {
|
|
551
|
+
this.transport = transport;
|
|
552
|
+
this.contextId = contextId;
|
|
553
|
+
}
|
|
554
|
+
get base() {
|
|
555
|
+
return getContextApiPrefix(this.contextId);
|
|
556
|
+
}
|
|
557
|
+
/**
|
|
558
|
+
* Lists one page of live attributes, newest first (`GET /attributes`).
|
|
559
|
+
*
|
|
560
|
+
* Live means not superseded and inside its validity window. Superseded
|
|
561
|
+
* values are reachable through the entity history endpoints.
|
|
562
|
+
*/
|
|
563
|
+
async attributes(options) {
|
|
564
|
+
const query = {};
|
|
565
|
+
if (options?.entity !== void 0) query.entity = options.entity;
|
|
566
|
+
if (options?.key !== void 0) query.key = options.key;
|
|
567
|
+
addPageParams(query, options);
|
|
568
|
+
const body = await this.transport.requestJson("GET", `${this.base}/attributes`, { query });
|
|
569
|
+
return body;
|
|
570
|
+
}
|
|
571
|
+
/** Every matching attribute, following cursors to exhaustion. */
|
|
572
|
+
async allAttributes(options) {
|
|
573
|
+
return collectPages((cursor) => this.attributes({
|
|
574
|
+
...options,
|
|
575
|
+
cursor
|
|
576
|
+
}), "attributes", options?.max);
|
|
577
|
+
}
|
|
578
|
+
/**
|
|
579
|
+
* Lists one page of live relation edges, newest first (`GET /relations`).
|
|
580
|
+
*
|
|
581
|
+
* `src` and `dst` filter one direction each. An entity's whole edge set is
|
|
582
|
+
* the union of both walks — see {@link Facts.allEdgesOf}, which does that
|
|
583
|
+
* for you.
|
|
584
|
+
*/
|
|
585
|
+
async relations(options) {
|
|
586
|
+
const query = {};
|
|
587
|
+
if (options?.src !== void 0) query.src = options.src;
|
|
588
|
+
if (options?.dst !== void 0) query.dst = options.dst;
|
|
589
|
+
if (options?.label !== void 0) query.label = options.label;
|
|
590
|
+
addPageParams(query, options);
|
|
591
|
+
const body = await this.transport.requestJson("GET", `${this.base}/relations`, { query });
|
|
592
|
+
return body;
|
|
593
|
+
}
|
|
594
|
+
/** Every matching relation, following cursors to exhaustion. */
|
|
595
|
+
async allRelations(options) {
|
|
596
|
+
return collectPages((cursor) => this.relations({
|
|
597
|
+
...options,
|
|
598
|
+
cursor
|
|
599
|
+
}), "relations", options?.max);
|
|
600
|
+
}
|
|
601
|
+
/**
|
|
602
|
+
* Every edge touching an entity, in both directions.
|
|
603
|
+
*
|
|
604
|
+
* This is what a truncated relation section points at. `src` and `dst` are
|
|
605
|
+
* separate filters, so either walk alone reproduces half the set that
|
|
606
|
+
* `entities.get` and `lookup` return; this runs both and concatenates them,
|
|
607
|
+
* outbound first.
|
|
608
|
+
*
|
|
609
|
+
* @param entity The subject, as `<type>/<name>`.
|
|
610
|
+
*/
|
|
611
|
+
async allEdgesOf(entity, options) {
|
|
612
|
+
const [outbound, inbound] = await Promise.all([this.allRelations({
|
|
613
|
+
src: entity,
|
|
614
|
+
label: options?.label,
|
|
615
|
+
limit: options?.limit
|
|
616
|
+
}), this.allRelations({
|
|
617
|
+
dst: entity,
|
|
618
|
+
label: options?.label,
|
|
619
|
+
limit: options?.limit
|
|
620
|
+
})]);
|
|
621
|
+
return [...outbound, ...inbound];
|
|
622
|
+
}
|
|
623
|
+
/**
|
|
624
|
+
* Lists one page of live actions — dated events — newest first by write
|
|
625
|
+
* time (`GET /actions`).
|
|
626
|
+
*
|
|
627
|
+
* Ordered on write time rather than event time because event time is
|
|
628
|
+
* revisable, and a revision under an event-time ordering would move a row
|
|
629
|
+
* across page boundaries mid-walk. `since` and `until` still bound the
|
|
630
|
+
* event time.
|
|
631
|
+
*/
|
|
632
|
+
async actions(options) {
|
|
633
|
+
const query = {};
|
|
634
|
+
if (options?.actor !== void 0) query.actor = options.actor;
|
|
635
|
+
if (options?.verb !== void 0) query.verb = options.verb;
|
|
636
|
+
if (options?.since !== void 0) query.since = options.since;
|
|
637
|
+
if (options?.until !== void 0) query.until = options.until;
|
|
638
|
+
addPageParams(query, options);
|
|
639
|
+
const body = await this.transport.requestJson("GET", `${this.base}/actions`, { query });
|
|
640
|
+
return body;
|
|
641
|
+
}
|
|
642
|
+
/** Every matching action, following cursors to exhaustion. */
|
|
643
|
+
async allActions(options) {
|
|
644
|
+
return collectPages((cursor) => this.actions({
|
|
645
|
+
...options,
|
|
646
|
+
cursor
|
|
647
|
+
}), "actions", options?.max);
|
|
414
648
|
}
|
|
415
649
|
};
|
|
416
650
|
|
|
@@ -734,6 +968,84 @@ var Traces = class {
|
|
|
734
968
|
}
|
|
735
969
|
};
|
|
736
970
|
|
|
971
|
+
//#endregion
|
|
972
|
+
//#region src/components/uncertainty.ts
|
|
973
|
+
/**
|
|
974
|
+
* The things this context is unsure about, and the one write that settles one.
|
|
975
|
+
*
|
|
976
|
+
* `/state` collapses these to `{about, reason}`, which is enough to say
|
|
977
|
+
* something is unresolved and not enough to act on it. These rows carry the
|
|
978
|
+
* subject, so a flag can be linked to the entity it is about and settled.
|
|
979
|
+
*/
|
|
980
|
+
var Uncertainty = class {
|
|
981
|
+
transport;
|
|
982
|
+
contextId;
|
|
983
|
+
constructor(transport, contextId) {
|
|
984
|
+
this.transport = transport;
|
|
985
|
+
this.contextId = contextId;
|
|
986
|
+
}
|
|
987
|
+
get base() {
|
|
988
|
+
return `${getContextApiPrefix(this.contextId)}/uncertainty`;
|
|
989
|
+
}
|
|
990
|
+
/** Lists one page of uncertainty flags, newest first (`GET /uncertainty`). */
|
|
991
|
+
async list(options) {
|
|
992
|
+
const query = {};
|
|
993
|
+
if (options?.entity !== void 0) query.entity = options.entity;
|
|
994
|
+
if (options?.resolved !== void 0) query.resolved = options.resolved;
|
|
995
|
+
addPageParams(query, options);
|
|
996
|
+
const body = await this.transport.requestJson("GET", this.base, { query });
|
|
997
|
+
return body;
|
|
998
|
+
}
|
|
999
|
+
/** Every matching flag, following cursors to exhaustion. */
|
|
1000
|
+
async listAll(options) {
|
|
1001
|
+
return collectPages((cursor) => this.list({
|
|
1002
|
+
...options,
|
|
1003
|
+
cursor
|
|
1004
|
+
}), "unknowns");
|
|
1005
|
+
}
|
|
1006
|
+
/**
|
|
1007
|
+
* How many flags match, without fetching them.
|
|
1008
|
+
*
|
|
1009
|
+
* Asks for a single row with `count: true`, so the total is the only thing
|
|
1010
|
+
* paid for beyond one page bound.
|
|
1011
|
+
*/
|
|
1012
|
+
async count(options) {
|
|
1013
|
+
const page = await this.list({
|
|
1014
|
+
...options,
|
|
1015
|
+
limit: 1,
|
|
1016
|
+
count: true
|
|
1017
|
+
});
|
|
1018
|
+
return page.page.totalSize ?? page.unknowns.length;
|
|
1019
|
+
}
|
|
1020
|
+
/**
|
|
1021
|
+
* Settles a flag by accepting one value
|
|
1022
|
+
* (`POST /uncertainty/{id}/resolve`). Requires the `memory:write` grant.
|
|
1023
|
+
*
|
|
1024
|
+
* One call, three effects: the flag is claimed, `acceptedValue` is written
|
|
1025
|
+
* through the reconciler at the upsert trust prior, and the values it beats
|
|
1026
|
+
* are retired. The accepted value lands at the flag's own scope rather than
|
|
1027
|
+
* the caller's write anchors, because it has to replace the contenders
|
|
1028
|
+
* where they live.
|
|
1029
|
+
*
|
|
1030
|
+
* Settlement converges on retry rather than being transactional: a failure
|
|
1031
|
+
* after the value is written hands the flag back and reports it, and
|
|
1032
|
+
* repeating the call dedups the value and finishes the retirement.
|
|
1033
|
+
*
|
|
1034
|
+
* Only the two reconciler-raised kinds — a cross-provenance contradiction
|
|
1035
|
+
* and a confidence-floor hold — record the entity and key a written value
|
|
1036
|
+
* would need. A flag without one is refused with a `422`, so check
|
|
1037
|
+
* `resolvable` on the row before offering the action; it also accounts for
|
|
1038
|
+
* an already-settled flag and for one whose scope reaches beyond the
|
|
1039
|
+
* calling key's write region.
|
|
1040
|
+
*/
|
|
1041
|
+
async resolve(uncertaintyId, acceptedValue, options) {
|
|
1042
|
+
const payload = { acceptedValue };
|
|
1043
|
+
if (options?.note !== void 0) payload.note = options.note;
|
|
1044
|
+
const body = await this.transport.requestJson("POST", `${this.base}/${encodePathSegment(uncertaintyId)}/resolve`, { body: payload });
|
|
1045
|
+
return body.uncertainty;
|
|
1046
|
+
}
|
|
1047
|
+
};
|
|
1048
|
+
|
|
737
1049
|
//#endregion
|
|
738
1050
|
//#region src/errors.ts
|
|
739
1051
|
/** Base class for all Agent Memory client errors. */
|
|
@@ -1158,7 +1470,7 @@ var Transport = class Transport {
|
|
|
1158
1470
|
const headers = {
|
|
1159
1471
|
Accept: accept,
|
|
1160
1472
|
Authorization: `Bearer ${this.apiKey}`,
|
|
1161
|
-
"User-Agent": `surrealdb-memory-js/1.0.0-alpha.
|
|
1473
|
+
"User-Agent": `surrealdb-memory-js/1.0.0-alpha.11`
|
|
1162
1474
|
};
|
|
1163
1475
|
if (this.onBehalfOf) headers["X-Spectron-On-Behalf-Of"] = this.onBehalfOf;
|
|
1164
1476
|
return headers;
|
|
@@ -1368,8 +1680,12 @@ var AgentMemory = class AgentMemory {
|
|
|
1368
1680
|
contextId;
|
|
1369
1681
|
/** Document ingestion, retrieval, corpus search, and the keyword graph. */
|
|
1370
1682
|
documents;
|
|
1371
|
-
/** Entity records, attributes, relations, and attribute history. */
|
|
1683
|
+
/** Entity records, attributes, relations, name search, and attribute history. */
|
|
1372
1684
|
entities;
|
|
1685
|
+
/** The attribute, relation, and action collections a bounded head points at. */
|
|
1686
|
+
facts;
|
|
1687
|
+
/** Things the context is unsure about, and the write that settles one. */
|
|
1688
|
+
uncertainty;
|
|
1373
1689
|
/** Conversation sessions for this context. */
|
|
1374
1690
|
sessions;
|
|
1375
1691
|
/** Expiry and decay sweeps. */
|
|
@@ -1395,6 +1711,8 @@ var AgentMemory = class AgentMemory {
|
|
|
1395
1711
|
const components = AgentMemory.buildComponents(this.transport, this.contextId);
|
|
1396
1712
|
this.documents = components.documents;
|
|
1397
1713
|
this.entities = components.entities;
|
|
1714
|
+
this.facts = components.facts;
|
|
1715
|
+
this.uncertainty = components.uncertainty;
|
|
1398
1716
|
this.sessions = components.sessions;
|
|
1399
1717
|
this.lifecycle = components.lifecycle;
|
|
1400
1718
|
this.traces = components.traces;
|
|
@@ -1406,6 +1724,8 @@ var AgentMemory = class AgentMemory {
|
|
|
1406
1724
|
return {
|
|
1407
1725
|
documents: new Documents(transport, contextId),
|
|
1408
1726
|
entities: new Entities(transport, contextId),
|
|
1727
|
+
facts: new Facts(transport, contextId),
|
|
1728
|
+
uncertainty: new Uncertainty(transport, contextId),
|
|
1409
1729
|
sessions: new Sessions(transport, contextId),
|
|
1410
1730
|
lifecycle: new Lifecycle(transport, contextId),
|
|
1411
1731
|
traces: new Traces(transport, contextId),
|
|
@@ -1521,6 +1841,46 @@ var AgentMemory = class AgentMemory {
|
|
|
1521
1841
|
const body = await this.transport.requestJson("POST", `${this.base}/chat`, { body: payload });
|
|
1522
1842
|
return body;
|
|
1523
1843
|
}
|
|
1844
|
+
/**
|
|
1845
|
+
* What this context knows about a subject, in one round trip
|
|
1846
|
+
* (`POST /lookup`).
|
|
1847
|
+
*
|
|
1848
|
+
* Everything returned is a stored row: nothing is generated, nothing is
|
|
1849
|
+
* summarised by a model, and an identical query returns an identical
|
|
1850
|
+
* answer. Branch on `resolution.kind` — `entity`, `topic`, `ambiguous`,
|
|
1851
|
+
* `empty` — rather than inferring which case you got from an array length.
|
|
1852
|
+
*
|
|
1853
|
+
* This is a composite aggregate like {@link AgentMemory.state}, not a
|
|
1854
|
+
* collection: every section is bounded and reports `truncated`, and none of
|
|
1855
|
+
* them page. To read a section in full, walk its own collection endpoint —
|
|
1856
|
+
* facts through `/attributes?entity=`, relations through **both**
|
|
1857
|
+
* `/relations?src=` and `/relations?dst=`, events through
|
|
1858
|
+
* `/actions?actor=`, passages through {@link AgentMemory.recall}, and
|
|
1859
|
+
* unknowns through {@link AgentMemory.uncertainty}. Note that `facts` is
|
|
1860
|
+
* ranked by importance while its collection pages in write order: the
|
|
1861
|
+
* ranked head is a different question from the walk, not its first page.
|
|
1862
|
+
*
|
|
1863
|
+
* Facts carry their source, trust and confidence but not the quoted
|
|
1864
|
+
* evidence text — a fact is one line until asked, and expanding one is a
|
|
1865
|
+
* passage read.
|
|
1866
|
+
*/
|
|
1867
|
+
async lookup(query, options) {
|
|
1868
|
+
const payload = { query };
|
|
1869
|
+
addDefined(payload, "subject", options?.subject);
|
|
1870
|
+
addDefined(payload, "entityType", options?.entityType);
|
|
1871
|
+
addDefined(payload, "ambiguityMargin", options?.ambiguityMargin);
|
|
1872
|
+
addDefined(payload, "include", options?.include);
|
|
1873
|
+
addDefined(payload, "factLimit", options?.factLimit);
|
|
1874
|
+
addDefined(payload, "relationLimit", options?.relationLimit);
|
|
1875
|
+
addDefined(payload, "eventLimit", options?.eventLimit);
|
|
1876
|
+
addDefined(payload, "passageLimit", options?.passageLimit);
|
|
1877
|
+
addDefined(payload, "uncertaintyLimit", options?.uncertaintyLimit);
|
|
1878
|
+
const body = await this.transport.requestJson("POST", `${this.base}/lookup`, {
|
|
1879
|
+
body: payload,
|
|
1880
|
+
idempotent: true
|
|
1881
|
+
});
|
|
1882
|
+
return body;
|
|
1883
|
+
}
|
|
1524
1884
|
/** Retrieves LLM-facing context text for a query without a session (`POST /context`). */
|
|
1525
1885
|
async context(query, options) {
|
|
1526
1886
|
const payload = { query };
|
|
@@ -1528,6 +1888,7 @@ var AgentMemory = class AgentMemory {
|
|
|
1528
1888
|
addDefined(payload, "labels", options?.labels);
|
|
1529
1889
|
addDefined(payload, "lens", normaliseScope(options?.lens));
|
|
1530
1890
|
addDefined(payload, "scopeView", options?.scopeView);
|
|
1891
|
+
addDefined(payload, "subject", options?.subject);
|
|
1531
1892
|
const body = await this.transport.requestJson("POST", `${this.base}/context`, {
|
|
1532
1893
|
body: payload,
|
|
1533
1894
|
idempotent: true
|
|
@@ -1606,11 +1967,13 @@ var AgentMemory = class AgentMemory {
|
|
|
1606
1967
|
* bounded by `limit` (default 100, max 500), and `truncated` reports which
|
|
1607
1968
|
* of them had more rows.
|
|
1608
1969
|
*
|
|
1609
|
-
*
|
|
1970
|
+
* Five of those tables have their own collection endpoint to enumerate them
|
|
1610
1971
|
* completely — entities (see {@link AgentMemory.entities}), attributes,
|
|
1611
|
-
* relations,
|
|
1612
|
-
*
|
|
1613
|
-
*
|
|
1972
|
+
* relations, actions, and `unknowns` (see
|
|
1973
|
+
* {@link AgentMemory.uncertainty}, which also returns the subject each flag
|
|
1974
|
+
* is about, where this snapshot collapses it to `{about, reason}`). Only
|
|
1975
|
+
* `instructions` has no such route: when `truncated` flags it, the omitted
|
|
1976
|
+
* rows cannot be recovered other than by raising `limit`.
|
|
1614
1977
|
*/
|
|
1615
1978
|
async state(options) {
|
|
1616
1979
|
const query = {};
|
|
@@ -1680,6 +2043,36 @@ const ScopeView = {
|
|
|
1680
2043
|
merged: "merged",
|
|
1681
2044
|
crossTeam: "crossTeam"
|
|
1682
2045
|
};
|
|
2046
|
+
/**
|
|
2047
|
+
* Ordering for the ranked entity head at `/entities/top`.
|
|
2048
|
+
*
|
|
2049
|
+
* `coverage` is most-known-about and the one ordering the entity listing cannot
|
|
2050
|
+
* express, but it costs an exact aggregate pass per fact family. `importance`
|
|
2051
|
+
* and `recency` are index-served single-table reads: prefer them where the
|
|
2052
|
+
* ranking need not be exact.
|
|
2053
|
+
*/
|
|
2054
|
+
const EntityRanking = {
|
|
2055
|
+
coverage: "coverage",
|
|
2056
|
+
importance: "importance",
|
|
2057
|
+
recency: "recency"
|
|
2058
|
+
};
|
|
2059
|
+
/**
|
|
2060
|
+
* The sections `/lookup` can be asked to fill.
|
|
2061
|
+
*
|
|
2062
|
+
* Everything but `passages` is on by default, because `passages` costs a
|
|
2063
|
+
* retrieval pass. An omitted section comes back empty with `truncated` false:
|
|
2064
|
+
* it was declined, not cut short. Unknown names are ignored by the server.
|
|
2065
|
+
*
|
|
2066
|
+
* `entities` is absent deliberately — it is not selectable. The server fills it
|
|
2067
|
+
* for a topic answer and leaves it empty for an entity one.
|
|
2068
|
+
*/
|
|
2069
|
+
const LookupSection = {
|
|
2070
|
+
facts: "facts",
|
|
2071
|
+
relations: "relations",
|
|
2072
|
+
events: "events",
|
|
2073
|
+
passages: "passages",
|
|
2074
|
+
uncertainty: "uncertainty"
|
|
2075
|
+
};
|
|
1683
2076
|
/** Document pipeline status values returned by the API. */
|
|
1684
2077
|
const DocumentStatus = {
|
|
1685
2078
|
queued: "queued",
|
|
@@ -1693,4 +2086,4 @@ const DocumentStatus = {
|
|
|
1693
2086
|
};
|
|
1694
2087
|
|
|
1695
2088
|
//#endregion
|
|
1696
|
-
export { AgentMemory, AgentMemoryError, AuthError, BatchExtractionMode, CancelledError, ConnectionError, DocumentKeywords, DocumentStatus, Documents, Entities, InferMode, Keys, Lifecycle, MemoryCategory, NotFoundError, Principals, QueryMode, RateLimitError, ScopeError, ScopeView, Scopes, ServerError, Session, Sessions, StreamError, Traces, Transport, TurnRole, ValidationError, Verb, addPageParams, agentMemoryFileInputToBlob, backoffSchedule, collectPages, encodePathSegment, errorFromResponse, getContextApiPrefix, idempotencyKey, normaliseScope, parseChatStream, shouldRetry, walkPages };
|
|
2089
|
+
export { AgentMemory, AgentMemoryError, AuthError, BatchExtractionMode, CancelledError, ConnectionError, DocumentKeywords, DocumentStatus, Documents, Entities, EntityRanking, Facts, InferMode, Keys, Lifecycle, LookupSection, MemoryCategory, NotFoundError, Principals, QueryMode, RateLimitError, ScopeError, ScopeView, Scopes, ServerError, Session, Sessions, StreamError, Traces, Transport, TurnRole, Uncertainty, ValidationError, Verb, addPageParams, agentMemoryFileInputToBlob, backoffSchedule, collectPages, encodePathSegment, errorFromResponse, getContextApiPrefix, idempotencyKey, normaliseScope, parseChatStream, shouldRetry, walkPages };
|