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