dsh-mnemon-source-memory-spaces 0.5.15 → 0.5.16

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.
@@ -229,6 +229,11 @@ declare const EDGE_TYPES: readonly ["temporal", "semantic", "causal", "entity"];
229
229
  type Intent = 'WHY' | 'WHEN' | 'ENTITY' | 'GENERAL';
230
230
  declare const INTENTS: readonly ["WHY", "WHEN", "ENTITY", "GENERAL"];
231
231
  type RecallRelevanceTier = 'high' | 'medium' | 'low' | 'unknown';
232
+ /**
233
+ * One spelling-insensitive key per entity. The Host's entity index and the Client's graph
234
+ * both count an entity's memories by it, so their numbers agree.
235
+ */
236
+ declare function normalizeEntityKey(entity: string): string;
232
237
  interface Insight {
233
238
  id: string;
234
239
  content: string;
@@ -347,7 +352,8 @@ interface MemoryGraphSnapshot {
347
352
  sources?: MemoryReadSource[];
348
353
  }
349
354
  type MemoryReadMode = 'search' | 'graph' | 'projection' | 'enumerable' | 'query-only' | 'entities' | 'unsupported';
350
- type MemoryReadStatus = 'ready' | 'empty' | 'query-required' | 'unsupported' | 'unavailable';
355
+ /** 'loading' is client-only: a page shows its spaces from the directory while the read runs. */
356
+ type MemoryReadStatus = 'ready' | 'empty' | 'query-required' | 'unsupported' | 'unavailable' | 'loading';
351
357
  /**
352
358
  * One provider-backed Memory Space participating in a read surface.
353
359
  *
@@ -365,6 +371,10 @@ interface MemoryReadSource {
365
371
  status: MemoryReadStatus;
366
372
  itemCount: number;
367
373
  edgeCount?: number;
374
+ /** Entity reads: the memories the entity index covers in this space. */
375
+ memoryCount?: number;
376
+ /** Entity reads: false when the Provider could not index every memory of this space. */
377
+ complete?: boolean;
368
378
  hint?: string;
369
379
  quality?: RecallQualityStats;
370
380
  }
@@ -499,15 +509,40 @@ interface MemorySpacesStatus {
499
509
  dbPath?: string;
500
510
  };
501
511
  }
512
+ /**
513
+ * The entities of the active spaces. Each count is the number of memories that
514
+ * carry the entity, the same set entity-memories lists.
515
+ */
502
516
  interface EntityView {
503
517
  items: Array<{
504
518
  entity: string;
505
519
  count: number;
506
520
  }>;
521
+ /** With a selected entity: the first page of entity-memories, kept for existing callers. */
507
522
  insights: Insight[];
508
523
  selected?: string;
509
524
  /** Omitted only when talking to a pre-provider-aware Host. */
510
525
  sources?: MemoryReadSource[];
526
+ /** Distinct entities across the active spaces; items may be capped below it. Omitted by older Hosts. */
527
+ total?: number;
528
+ /** False when a space's Provider could not index every memory. Omitted by older Hosts. */
529
+ complete?: boolean;
530
+ }
531
+ /** One page of the memories that carry an entity, by importance and then recency. */
532
+ interface EntityMemoriesView {
533
+ /** The entity's most common spelling, or the requested name when no memory carries it. */
534
+ entity: string;
535
+ total: number;
536
+ offset: number;
537
+ items: Insight[];
538
+ complete: boolean;
539
+ sources: MemoryReadSource[];
540
+ }
541
+ /** Memories recall relates to an entity that do not carry it themselves. */
542
+ interface EntityRelatedView {
543
+ entity: string;
544
+ items: Insight[];
545
+ sources: MemoryReadSource[];
511
546
  }
512
547
  /** @deprecated Use CreateMemorySpaceRequest. The wire shape is unchanged. */
513
548
  type CreateMemoryBodyRequest = CreateMemorySpaceRequest;
@@ -532,4 +567,4 @@ type MemoryBodyView = MemorySpaceView;
532
567
  /** @deprecated Use OpenVikingSpaceConnection. The wire shape is unchanged. */
533
568
  type OpenVikingBodyConnection = OpenVikingSpaceConnection;
534
569
  //#endregion
535
- export { AutomaticMemoryPlacementRequest, CATEGORIES, Category, CreateMemoryBodyRequest, CreateMemorySpaceRequest, DEFAULT_EMBEDDING_ENDPOINT, DEFAULT_EMBEDDING_MODEL, DEFAULT_EMBEDDING_PROTOCOL, EDGE_TYPES, EMBEDDING_PROTOCOL_AUTO, EMBEDDING_PROTOCOL_OLLAMA, EMBEDDING_PROTOCOL_OPENAI, EdgeType, EntityView, INTENTS, Insight, Intent, type JsonValue, LlmMemoryPlacementSelection, MNEMON_EMBEDDING_PROTOCOLS, MemoryBody, MemoryBodyCatalog, MemoryBodyMetadataMaintenanceResult, MemoryBodyMetadataSample, MemoryBodyMetadataUpdate, MemoryBodyProvider, MemoryBodyStats, MemoryBodyView, MemoryGraphEdge, MemoryGraphNode, MemoryGraphSnapshot, MemoryListRequest, MemoryListView, MemoryPersistenceStrategy, MemoryPlacementCandidate, MemoryPlacementCapability, MemoryPlacementDecision, MemoryPlacementPreference, MemoryPlacementRules, MemoryProviderCapabilities, MemoryProviderConfigField, MemoryProviderConfigOption, MemoryProviderConnection, MemoryProviderConnectionValue, MemoryProviderDescriptor, MemoryProviderIcon, MemoryProviderId, MemoryProviderRuntimeStatus, MemoryProviderServiceCatalog, MemoryProviderServiceView, MemoryReadMode, MemoryReadSource, MemoryReadStatus, MemorySpace, MemorySpaceCatalog, MemorySpaceMetadataMaintenanceResult, MemorySpaceMetadataSample, MemorySpaceMetadataUpdate, MemorySpaceProvider, MemorySpaceStats, MemorySpaceView, MemorySpaceWriteScope, MemorySpaceWriteScopeRequest, MemorySpacesStatus, MnemonEmbeddingConfig, MnemonEmbeddingProtocol, MnemonEmbeddingStatus, OpenVikingBodyConnection, OpenVikingSpaceConnection, PreparedMemoryPlacement, RecallQualityConfig, RecallQualityStats, RecallRelevanceTier, RememberRequest, ResolvedMemoryPersistenceStrategy, ResolvedMnemonEmbeddingConfig, ResolvedRecallQualityConfig, SOURCES, SearchRequest, Source, UpdateMemoryBodyRequest, UpdateMemoryProviderServiceRequest, UpdateMemorySpaceRequest };
570
+ export { AutomaticMemoryPlacementRequest, CATEGORIES, Category, CreateMemoryBodyRequest, CreateMemorySpaceRequest, DEFAULT_EMBEDDING_ENDPOINT, DEFAULT_EMBEDDING_MODEL, DEFAULT_EMBEDDING_PROTOCOL, EDGE_TYPES, EMBEDDING_PROTOCOL_AUTO, EMBEDDING_PROTOCOL_OLLAMA, EMBEDDING_PROTOCOL_OPENAI, EdgeType, EntityMemoriesView, EntityRelatedView, EntityView, INTENTS, Insight, Intent, type JsonValue, LlmMemoryPlacementSelection, MNEMON_EMBEDDING_PROTOCOLS, MemoryBody, MemoryBodyCatalog, MemoryBodyMetadataMaintenanceResult, MemoryBodyMetadataSample, MemoryBodyMetadataUpdate, MemoryBodyProvider, MemoryBodyStats, MemoryBodyView, MemoryGraphEdge, MemoryGraphNode, MemoryGraphSnapshot, MemoryListRequest, MemoryListView, MemoryPersistenceStrategy, MemoryPlacementCandidate, MemoryPlacementCapability, MemoryPlacementDecision, MemoryPlacementPreference, MemoryPlacementRules, MemoryProviderCapabilities, MemoryProviderConfigField, MemoryProviderConfigOption, MemoryProviderConnection, MemoryProviderConnectionValue, MemoryProviderDescriptor, MemoryProviderIcon, MemoryProviderId, MemoryProviderRuntimeStatus, MemoryProviderServiceCatalog, MemoryProviderServiceView, MemoryReadMode, MemoryReadSource, MemoryReadStatus, MemorySpace, MemorySpaceCatalog, MemorySpaceMetadataMaintenanceResult, MemorySpaceMetadataSample, MemorySpaceMetadataUpdate, MemorySpaceProvider, MemorySpaceStats, MemorySpaceView, MemorySpaceWriteScope, MemorySpaceWriteScopeRequest, MemorySpacesStatus, MnemonEmbeddingConfig, MnemonEmbeddingProtocol, MnemonEmbeddingStatus, OpenVikingBodyConnection, OpenVikingSpaceConnection, PreparedMemoryPlacement, RecallQualityConfig, RecallQualityStats, RecallRelevanceTier, RememberRequest, ResolvedMemoryPersistenceStrategy, ResolvedMnemonEmbeddingConfig, ResolvedRecallQualityConfig, SOURCES, SearchRequest, Source, UpdateMemoryBodyRequest, UpdateMemoryProviderServiceRequest, UpdateMemorySpaceRequest, normalizeEntityKey };
package/lib/contracts.js CHANGED
@@ -24,6 +24,13 @@ const INTENTS = [
24
24
  "ENTITY",
25
25
  "GENERAL"
26
26
  ];
27
+ /**
28
+ * One spelling-insensitive key per entity. The Host's entity index and the Client's graph
29
+ * both count an entity's memories by it, so their numbers agree.
30
+ */
31
+ function normalizeEntityKey(entity) {
32
+ return entity.normalize("NFKC").trim().toLocaleLowerCase();
33
+ }
27
34
  const DEFAULT_EMBEDDING_ENDPOINT = "http://localhost:11434";
28
35
  const DEFAULT_EMBEDDING_MODEL = "nomic-embed-text";
29
36
  const EMBEDDING_PROTOCOL_AUTO = "auto";
@@ -38,4 +45,4 @@ const MNEMON_EMBEDDING_PROTOCOLS = [
38
45
  EMBEDDING_PROTOCOL_OPENAI
39
46
  ];
40
47
  //#endregion
41
- export { CATEGORIES, DEFAULT_EMBEDDING_ENDPOINT, DEFAULT_EMBEDDING_MODEL, DEFAULT_EMBEDDING_PROTOCOL, EDGE_TYPES, EMBEDDING_PROTOCOL_AUTO, EMBEDDING_PROTOCOL_OLLAMA, EMBEDDING_PROTOCOL_OPENAI, INTENTS, MNEMON_EMBEDDING_PROTOCOLS, SOURCES };
48
+ export { CATEGORIES, DEFAULT_EMBEDDING_ENDPOINT, DEFAULT_EMBEDDING_MODEL, DEFAULT_EMBEDDING_PROTOCOL, EDGE_TYPES, EMBEDDING_PROTOCOL_AUTO, EMBEDDING_PROTOCOL_OLLAMA, EMBEDDING_PROTOCOL_OPENAI, INTENTS, MNEMON_EMBEDDING_PROTOCOLS, SOURCES, normalizeEntityKey };
@@ -51,6 +51,13 @@ interface ProviderScoreSemantics {
51
51
  }
52
52
  type MemoryProviderScoreSemantics = 'normalized-relevance' | 'provider-native' | 'none';
53
53
  declare const NORMALIZED_RELEVANCE_SCORE: ProviderScoreSemantics;
54
+ /** The memories of one Memory Space that carry entities, as the Provider's own index has them. */
55
+ interface ProviderEntityIndex {
56
+ /** Each memory with at least one entity, listing its entities. */
57
+ memories: Insight[];
58
+ /** False when the Provider could not include every memory of the space. */
59
+ complete: boolean;
60
+ }
54
61
  /** One provider-owned namespace projected into DSH as a Memory Space. */
55
62
  interface ProviderMemorySpace {
56
63
  /** Stable identifier owned by the provider, never a DSH-generated title. */
@@ -77,6 +84,12 @@ interface MemoryProviderAdapter {
77
84
  remember(body: MemorySpace, request: RememberRequest, signal?: AbortSignal): Promise<JsonValue>;
78
85
  /** Optional cheap bounded metadata sampling, without a graph projection. */
79
86
  metadataSample?(body: MemorySpace, limit: number, signal?: AbortSignal): Promise<Insight[]>;
87
+ /**
88
+ * Optional entity index for the Entities page. Without it the Source builds
89
+ * the index from list(), so a Provider whose list() stops short of every
90
+ * memory, or that cannot list, implements this to keep entity counts whole.
91
+ */
92
+ entityIndex?(body: MemorySpace, signal?: AbortSignal): Promise<ProviderEntityIndex>;
80
93
  /** Persist an ordered host-authorized batch and return one receipt per request. */
81
94
  rememberMany?(body: MemorySpace, requests: readonly RememberRequest[], signal?: AbortSignal): Promise<JsonValue[]>;
82
95
  related?(body: MemorySpace, id: string, depth: number, edge?: EdgeType, signal?: AbortSignal): Promise<Insight[]>;
@@ -142,4 +155,4 @@ interface MemorySpaceProviderEntry<Config = unknown> {
142
155
  declare function defineMemorySpaceProvider<Config>(module: MemorySpaceProviderModule<Config>): MemorySpaceProviderModule<Config>;
143
156
  declare function defineMemorySpaceProviderDefinition(definition: MemorySpaceProviderDefinition): MemorySpaceProviderDefinition;
144
157
  //#endregion
145
- export { ProviderSpaceStatus as C, ProviderSearchResult as S, MemorySpaceNativeRunner as _, MemorySpaceProviderHost as a, ProviderMemorySpace as b, MemorySpaceProviderRuntimeContext as c, defineMemorySpaceProviderDefinition as d, MemoryProviderAdapter as f, MemorySpaceNativeRunOptions as g, MemorySpaceAuthority as h, MemorySpaceProviderEntry as i, MemorySpaceProviderScoreSemantics as l, MemoryProviderScoreSemantics as m, MemorySpaceProviderDefinition as n, MemorySpaceProviderManifest as o, MemoryProviderAdapterFactoryContext as p, MemorySpaceProviderDisposer as r, MemorySpaceProviderModule as s, MEMORY_SPACE_PROVIDER_API_VERSION as t, defineMemorySpaceProvider as u, NORMALIZED_RELEVANCE_SCORE as v, ProviderScoreSemantics as x, ProviderBodyStatus as y };
158
+ export { ProviderSearchResult as C, ProviderScoreSemantics as S, MemorySpaceNativeRunner as _, MemorySpaceProviderHost as a, ProviderEntityIndex as b, MemorySpaceProviderRuntimeContext as c, defineMemorySpaceProviderDefinition as d, MemoryProviderAdapter as f, MemorySpaceNativeRunOptions as g, MemorySpaceAuthority as h, MemorySpaceProviderEntry as i, MemorySpaceProviderScoreSemantics as l, MemoryProviderScoreSemantics as m, MemorySpaceProviderDefinition as n, MemorySpaceProviderManifest as o, MemoryProviderAdapterFactoryContext as p, MemorySpaceProviderDisposer as r, MemorySpaceProviderModule as s, MEMORY_SPACE_PROVIDER_API_VERSION as t, defineMemorySpaceProvider as u, NORMALIZED_RELEVANCE_SCORE as v, ProviderSpaceStatus as w, ProviderMemorySpace as x, ProviderBodyStatus as y };
package/lib/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { AutomaticMemoryPlacementRequest, CATEGORIES, Category, CreateMemoryBodyRequest, CreateMemorySpaceRequest, DEFAULT_EMBEDDING_ENDPOINT, DEFAULT_EMBEDDING_MODEL, DEFAULT_EMBEDDING_PROTOCOL, EDGE_TYPES, EMBEDDING_PROTOCOL_AUTO, EMBEDDING_PROTOCOL_OLLAMA, EMBEDDING_PROTOCOL_OPENAI, EdgeType, EntityView, INTENTS, Insight, Intent, JsonValue, LlmMemoryPlacementSelection, MNEMON_EMBEDDING_PROTOCOLS, MemoryBody, MemoryBodyCatalog, MemoryBodyMetadataMaintenanceResult, MemoryBodyMetadataSample, MemoryBodyMetadataUpdate, MemoryBodyProvider, MemoryBodyStats, MemoryBodyView, MemoryGraphEdge, MemoryGraphNode, MemoryGraphSnapshot, MemoryListRequest, MemoryListView, MemoryPersistenceStrategy, MemoryPlacementCandidate, MemoryPlacementCapability, MemoryPlacementDecision, MemoryPlacementPreference, MemoryPlacementRules, MemoryProviderCapabilities, MemoryProviderConfigField, MemoryProviderConfigOption, MemoryProviderConnection, MemoryProviderConnectionValue, MemoryProviderDescriptor, MemoryProviderIcon, MemoryProviderId, MemoryProviderRuntimeStatus, MemoryProviderServiceCatalog, MemoryProviderServiceView, MemoryReadMode, MemoryReadSource, MemoryReadStatus, MemorySpace, MemorySpaceCatalog, MemorySpaceMetadataMaintenanceResult, MemorySpaceMetadataSample, MemorySpaceMetadataUpdate, MemorySpaceProvider, MemorySpaceStats, MemorySpaceView, MemorySpaceWriteScope, MemorySpaceWriteScopeRequest, MemorySpacesStatus, MnemonEmbeddingConfig, MnemonEmbeddingProtocol, MnemonEmbeddingStatus, OpenVikingBodyConnection, OpenVikingSpaceConnection, PreparedMemoryPlacement, RecallQualityConfig, RecallQualityStats, RecallRelevanceTier, RememberRequest, ResolvedMemoryPersistenceStrategy, ResolvedMnemonEmbeddingConfig, ResolvedRecallQualityConfig, SOURCES, SearchRequest, Source, UpdateMemoryBodyRequest, UpdateMemoryProviderServiceRequest, UpdateMemorySpaceRequest } from "./contracts.js";
2
- import { i as MemorySpaceProviderEntry } from "./definitions-DwiEZSE_.js";
1
+ import { AutomaticMemoryPlacementRequest, CATEGORIES, Category, CreateMemoryBodyRequest, CreateMemorySpaceRequest, DEFAULT_EMBEDDING_ENDPOINT, DEFAULT_EMBEDDING_MODEL, DEFAULT_EMBEDDING_PROTOCOL, EDGE_TYPES, EMBEDDING_PROTOCOL_AUTO, EMBEDDING_PROTOCOL_OLLAMA, EMBEDDING_PROTOCOL_OPENAI, EdgeType, EntityMemoriesView, EntityRelatedView, EntityView, INTENTS, Insight, Intent, JsonValue, LlmMemoryPlacementSelection, MNEMON_EMBEDDING_PROTOCOLS, MemoryBody, MemoryBodyCatalog, MemoryBodyMetadataMaintenanceResult, MemoryBodyMetadataSample, MemoryBodyMetadataUpdate, MemoryBodyProvider, MemoryBodyStats, MemoryBodyView, MemoryGraphEdge, MemoryGraphNode, MemoryGraphSnapshot, MemoryListRequest, MemoryListView, MemoryPersistenceStrategy, MemoryPlacementCandidate, MemoryPlacementCapability, MemoryPlacementDecision, MemoryPlacementPreference, MemoryPlacementRules, MemoryProviderCapabilities, MemoryProviderConfigField, MemoryProviderConfigOption, MemoryProviderConnection, MemoryProviderConnectionValue, MemoryProviderDescriptor, MemoryProviderIcon, MemoryProviderId, MemoryProviderRuntimeStatus, MemoryProviderServiceCatalog, MemoryProviderServiceView, MemoryReadMode, MemoryReadSource, MemoryReadStatus, MemorySpace, MemorySpaceCatalog, MemorySpaceMetadataMaintenanceResult, MemorySpaceMetadataSample, MemorySpaceMetadataUpdate, MemorySpaceProvider, MemorySpaceStats, MemorySpaceView, MemorySpaceWriteScope, MemorySpaceWriteScopeRequest, MemorySpacesStatus, MnemonEmbeddingConfig, MnemonEmbeddingProtocol, MnemonEmbeddingStatus, OpenVikingBodyConnection, OpenVikingSpaceConnection, PreparedMemoryPlacement, RecallQualityConfig, RecallQualityStats, RecallRelevanceTier, RememberRequest, ResolvedMemoryPersistenceStrategy, ResolvedMnemonEmbeddingConfig, ResolvedRecallQualityConfig, SOURCES, SearchRequest, Source, UpdateMemoryBodyRequest, UpdateMemoryProviderServiceRequest, UpdateMemorySpaceRequest, normalizeEntityKey } from "./contracts.js";
2
+ import { i as MemorySpaceProviderEntry } from "./definitions-BcYzE092.js";
3
3
  import z from "@deepseek-ai/schemastery";
4
4
  import { Context } from "@deepseek-ai/cordis";
5
5
  //#region src/config.d.ts
@@ -59,4 +59,4 @@ declare function resolveMemorySpaceProviderEntries(ctx: Context, declarations: r
59
59
  declare function installMemorySpaces(ctx: Context, entries: readonly MemorySpaceProviderEntry[], options?: InstallMemorySpacesOptions): Promise<void>;
60
60
  declare function apply(ctx: Context, config?: Config): Promise<void>;
61
61
  //#endregion
62
- export { type AutomaticMemoryPlacementRequest, type CATEGORIES, type Category, Config, type CreateMemoryBodyRequest, type CreateMemorySpaceRequest, type DEFAULT_EMBEDDING_ENDPOINT, type DEFAULT_EMBEDDING_MODEL, type DEFAULT_EMBEDDING_PROTOCOL, type EDGE_TYPES, type EMBEDDING_PROTOCOL_AUTO, type EMBEDDING_PROTOCOL_OLLAMA, type EMBEDDING_PROTOCOL_OPENAI, type EdgeType, type EntityView, type INTENTS, type Insight, InstallMemorySpacesOptions, type Intent, type JsonValue, type LlmMemoryPlacementSelection, type MNEMON_EMBEDDING_PROTOCOLS, type MemoryBody, type MemoryBodyCatalog, type MemoryBodyMetadataMaintenanceResult, type MemoryBodyMetadataSample, type MemoryBodyMetadataUpdate, type MemoryBodyProvider, type MemoryBodyStats, type MemoryBodyView, type MemoryGraphEdge, type MemoryGraphNode, type MemoryGraphSnapshot, type MemoryListRequest, type MemoryListView, type MemoryPersistenceStrategy, type MemoryPlacementCandidate, type MemoryPlacementCapability, type MemoryPlacementDecision, type MemoryPlacementPreference, type MemoryPlacementRules, type MemoryProviderCapabilities, type MemoryProviderConfigField, type MemoryProviderConfigOption, type MemoryProviderConnection, type MemoryProviderConnectionValue, type MemoryProviderDescriptor, type MemoryProviderIcon, type MemoryProviderId, type MemoryProviderRuntimeStatus, type MemoryProviderServiceCatalog, type MemoryProviderServiceView, type MemoryReadMode, type MemoryReadSource, type MemoryReadStatus, type MemorySpace, type MemorySpaceCatalog, type MemorySpaceMetadataMaintenanceResult, type MemorySpaceMetadataSample, type MemorySpaceMetadataUpdate, type MemorySpaceProvider, MemorySpaceProviderDeclaration, MemorySpaceProviderDeclarationSchema, type MemorySpaceStats, type MemorySpaceView, type MemorySpaceWriteScope, type MemorySpaceWriteScopeRequest, type MemorySpacesStatus, type MnemonEmbeddingConfig, type MnemonEmbeddingProtocol, type MnemonEmbeddingStatus, type OpenVikingBodyConnection, type OpenVikingSpaceConnection, type PreparedMemoryPlacement, type RecallQualityConfig, type RecallQualityStats, type RecallRelevanceTier, type RememberRequest, type ResolvedMemoryPersistenceStrategy, type ResolvedMnemonEmbeddingConfig, type ResolvedRecallQualityConfig, type SOURCES, type SearchRequest, type Source, type UpdateMemoryBodyRequest, type UpdateMemoryProviderServiceRequest, type UpdateMemorySpaceRequest, apply, inject, installMemorySpaces, memoryPlugin, name, resolveEmbedding, resolveMemorySpaceProviderEntries, resolvePersistenceStrategy, resolveRecallQuality };
62
+ export { type AutomaticMemoryPlacementRequest, type CATEGORIES, type Category, Config, type CreateMemoryBodyRequest, type CreateMemorySpaceRequest, type DEFAULT_EMBEDDING_ENDPOINT, type DEFAULT_EMBEDDING_MODEL, type DEFAULT_EMBEDDING_PROTOCOL, type EDGE_TYPES, type EMBEDDING_PROTOCOL_AUTO, type EMBEDDING_PROTOCOL_OLLAMA, type EMBEDDING_PROTOCOL_OPENAI, type EdgeType, type EntityMemoriesView, type EntityRelatedView, type EntityView, type INTENTS, type Insight, InstallMemorySpacesOptions, type Intent, type JsonValue, type LlmMemoryPlacementSelection, type MNEMON_EMBEDDING_PROTOCOLS, type MemoryBody, type MemoryBodyCatalog, type MemoryBodyMetadataMaintenanceResult, type MemoryBodyMetadataSample, type MemoryBodyMetadataUpdate, type MemoryBodyProvider, type MemoryBodyStats, type MemoryBodyView, type MemoryGraphEdge, type MemoryGraphNode, type MemoryGraphSnapshot, type MemoryListRequest, type MemoryListView, type MemoryPersistenceStrategy, type MemoryPlacementCandidate, type MemoryPlacementCapability, type MemoryPlacementDecision, type MemoryPlacementPreference, type MemoryPlacementRules, type MemoryProviderCapabilities, type MemoryProviderConfigField, type MemoryProviderConfigOption, type MemoryProviderConnection, type MemoryProviderConnectionValue, type MemoryProviderDescriptor, type MemoryProviderIcon, type MemoryProviderId, type MemoryProviderRuntimeStatus, type MemoryProviderServiceCatalog, type MemoryProviderServiceView, type MemoryReadMode, type MemoryReadSource, type MemoryReadStatus, type MemorySpace, type MemorySpaceCatalog, type MemorySpaceMetadataMaintenanceResult, type MemorySpaceMetadataSample, type MemorySpaceMetadataUpdate, type MemorySpaceProvider, MemorySpaceProviderDeclaration, MemorySpaceProviderDeclarationSchema, type MemorySpaceStats, type MemorySpaceView, type MemorySpaceWriteScope, type MemorySpaceWriteScopeRequest, type MemorySpacesStatus, type MnemonEmbeddingConfig, type MnemonEmbeddingProtocol, type MnemonEmbeddingStatus, type OpenVikingBodyConnection, type OpenVikingSpaceConnection, type PreparedMemoryPlacement, type RecallQualityConfig, type RecallQualityStats, type RecallRelevanceTier, type RememberRequest, type ResolvedMemoryPersistenceStrategy, type ResolvedMnemonEmbeddingConfig, type ResolvedRecallQualityConfig, type SOURCES, type SearchRequest, type Source, type UpdateMemoryBodyRequest, type UpdateMemoryProviderServiceRequest, type UpdateMemorySpaceRequest, apply, inject, installMemorySpaces, memoryPlugin, name, type normalizeEntityKey, resolveEmbedding, resolveMemorySpaceProviderEntries, resolvePersistenceStrategy, resolveRecallQuality };
package/lib/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { findMnemonCommand, isMnemonExecutable, resolveMnemonInvocation } from "./native-cli.js";
2
- import { CATEGORIES as CATEGORIES$1, EDGE_TYPES, INTENTS as INTENTS$1, MNEMON_EMBEDDING_PROTOCOLS, SOURCES as SOURCES$1 } from "./contracts.js";
2
+ import { CATEGORIES as CATEGORIES$1, EDGE_TYPES, INTENTS as INTENTS$1, MNEMON_EMBEDDING_PROTOCOLS, SOURCES as SOURCES$1, normalizeEntityKey } from "./contracts.js";
3
3
  import { a as MemoryProviderCatalog, i as EMPTY_MEMORY_PROVIDER_CATALOG, n as PrivateMemorySpaceProviderHost, r as MemoryProviderAdapterRegistry, t as createMemorySpaceProviderPlugin } from "./plugin-DlsNeZbQ.js";
4
4
  import { n as ProcessError, r as runProcess } from "./process-DIK9NnTg.js";
5
5
  import { r as defineMemorySpaceProvider } from "./definitions-DfmOqJjR.js";
@@ -999,6 +999,88 @@ function lexicalRequiredMatchCount(tokens) {
999
999
  return Math.max(2, Math.ceil(tokens.length / 4));
1000
1000
  }
1001
1001
  //#endregion
1002
+ //#region src/entity-index.ts
1003
+ /**
1004
+ * The most memories one space's derived index asks list() for. Mnemon Native
1005
+ * lists a whole store; a Provider that stops earlier reports what it listed.
1006
+ */
1007
+ const ENTITY_INDEX_LIST_LIMIT = 1e5;
1008
+ /** The rail lists at most this many entities; the rest stay reachable by name. */
1009
+ const ENTITY_RAIL_LIMIT = 5e3;
1010
+ function buildSpaceEntityIndex(memories, memoryCount, complete) {
1011
+ const kept = [];
1012
+ const byKey = /* @__PURE__ */ new Map();
1013
+ const spellings = /* @__PURE__ */ new Map();
1014
+ for (const memory of memories) {
1015
+ const seen = /* @__PURE__ */ new Set();
1016
+ let position;
1017
+ for (const raw of memory.entities ?? []) {
1018
+ if (typeof raw !== "string") continue;
1019
+ const key = normalizeEntityKey(raw);
1020
+ if (key === "" || seen.has(key)) continue;
1021
+ seen.add(key);
1022
+ if (position === void 0) {
1023
+ position = kept.length;
1024
+ kept.push(memory);
1025
+ }
1026
+ const positions = byKey.get(key);
1027
+ if (positions === void 0) byKey.set(key, [position]);
1028
+ else positions.push(position);
1029
+ const name = raw.normalize("NFKC").trim();
1030
+ const names = spellings.get(key);
1031
+ if (names === void 0) spellings.set(key, /* @__PURE__ */ new Map([[name, 1]]));
1032
+ else names.set(name, (names.get(name) ?? 0) + 1);
1033
+ }
1034
+ }
1035
+ return {
1036
+ memories: kept,
1037
+ byKey,
1038
+ spellings,
1039
+ memoryCount,
1040
+ complete
1041
+ };
1042
+ }
1043
+ /** The spelling most memories use; the first one seen wins a tie. */
1044
+ function preferredSpelling(names) {
1045
+ let preferred = "";
1046
+ let most = 0;
1047
+ for (const [name, count] of names) if (count > most) {
1048
+ preferred = name;
1049
+ most = count;
1050
+ }
1051
+ return preferred;
1052
+ }
1053
+ /** Merge per-space indexes into one entity list, most frequent first. */
1054
+ function mergeEntityCounts(indexes) {
1055
+ const counts = /* @__PURE__ */ new Map();
1056
+ const spellings = /* @__PURE__ */ new Map();
1057
+ for (const index of indexes) for (const [key, positions] of index.byKey) {
1058
+ counts.set(key, (counts.get(key) ?? 0) + positions.length);
1059
+ let totals = spellings.get(key);
1060
+ if (totals === void 0) spellings.set(key, totals = /* @__PURE__ */ new Map());
1061
+ for (const [name, count] of index.spellings.get(key) ?? []) totals.set(name, (totals.get(name) ?? 0) + count);
1062
+ }
1063
+ const names = /* @__PURE__ */ new Map();
1064
+ for (const [key, totals] of spellings) names.set(key, preferredSpelling(totals));
1065
+ return {
1066
+ items: [...counts].map(([key, count]) => ({
1067
+ entity: names.get(key),
1068
+ count
1069
+ })).sort((left, right) => right.count - left.count || left.entity.localeCompare(right.entity)),
1070
+ names
1071
+ };
1072
+ }
1073
+ /** Importance first, then the newest; the order Mnemon Native lists a store in. */
1074
+ function compareEntityMemories(left, right) {
1075
+ return (right.importance ?? 0) - (left.importance ?? 0) || (right.createdAt ?? "").localeCompare(left.createdAt ?? "") || (left.memoryBodyName ?? "").localeCompare(right.memoryBodyName ?? "") || left.id.localeCompare(right.id);
1076
+ }
1077
+ /** Every memory across the indexes that carries the entity key. */
1078
+ function memoriesWithEntity(indexes, key) {
1079
+ const memories = [];
1080
+ for (const index of indexes) for (const position of index.byKey.get(key) ?? []) memories.push(index.memories[position]);
1081
+ return memories.sort(compareEntityMemories);
1082
+ }
1083
+ //#endregion
1002
1084
  //#region src/recall-quality/policies.ts
1003
1085
  function expandedLimit(context) {
1004
1086
  return Math.min(50, Math.max(context.requestedLimit, Math.ceil(context.requestedLimit * context.config.candidateMultiplier)));
@@ -1208,6 +1290,39 @@ function text(value) {
1208
1290
  function number(value) {
1209
1291
  return typeof value === "number" && Number.isFinite(value) ? value : void 0;
1210
1292
  }
1293
+ /**
1294
+ * How long a selection reuses the Provider health its index was checked with.
1295
+ * The rail always checks again; a write through this Source drops both at once.
1296
+ */
1297
+ const ENTITY_SELECTION_STATUS_REUSE_MS = 1e4;
1298
+ /** How long an index that statistics cannot check is reused; a write through this Source still drops it. */
1299
+ const ENTITY_INDEX_UNCHECKED_REUSE_MS = 1e4;
1300
+ function entityName(entity) {
1301
+ const name = entity.trim();
1302
+ if (name.length > 200) throw new Error("entity is too long (max 200 characters)");
1303
+ return name;
1304
+ }
1305
+ function memoryKey(memoryBodyId, id) {
1306
+ return `${memoryBodyId}\u0000${id}`;
1307
+ }
1308
+ /**
1309
+ * What must stay the same for a space's entity index to stay valid: its
1310
+ * Provider statistics (Mnemon counts every write in its operation log) and the
1311
+ * Source's own record of the space. Without statistics it cannot be checked.
1312
+ */
1313
+ function entityIndexFingerprint(body, status) {
1314
+ const stats = status.stats;
1315
+ if (stats === void 0) return void 0;
1316
+ return JSON.stringify([
1317
+ body.provider.id,
1318
+ body.updatedAt,
1319
+ stats.totalInsights,
1320
+ stats.deletedInsights,
1321
+ stats.edgeCount,
1322
+ stats.oplogCount,
1323
+ stats.dbSizeBytes
1324
+ ]);
1325
+ }
1211
1326
  function readSource(body, mode, status, itemCount, options = {}) {
1212
1327
  return {
1213
1328
  memoryBodyId: body.id,
@@ -1377,6 +1492,12 @@ var MemorySpacesService = class {
1377
1492
  providers;
1378
1493
  recallQualityPolicy;
1379
1494
  spacesInFlight;
1495
+ /** One entity index per active entity space, valid while its fingerprint holds. */
1496
+ entityIndexCache = /* @__PURE__ */ new Map();
1497
+ /** settledAt stays undefined while the read runs, which every caller shares. */
1498
+ entityStatusCache = /* @__PURE__ */ new Map();
1499
+ /** The related read each page view is waiting for; a newer selection cancels the older one. */
1500
+ entityRelatedViews = /* @__PURE__ */ new Map();
1380
1501
  providersDisposed = false;
1381
1502
  /** The CLI version a full status last read, and the binary it read it from. */
1382
1503
  cliVersion;
@@ -1688,6 +1809,7 @@ var MemorySpacesService = class {
1688
1809
  }
1689
1810
  const provider = this.providerFor(body);
1690
1811
  provider.invalidateStatus?.(body.id);
1812
+ this.invalidateEntityIndex(body.id);
1691
1813
  const status = await provider.status(body, signal);
1692
1814
  return {
1693
1815
  ...body,
@@ -1696,7 +1818,8 @@ var MemorySpacesService = class {
1696
1818
  ...status
1697
1819
  };
1698
1820
  }
1699
- async search(request, signal) {
1821
+ /** exclude: memoryKey()s to leave out before the quality policy selects. */
1822
+ async search(request, signal, options = {}) {
1700
1823
  const query = required(request.query, "query", 2e3);
1701
1824
  const limit = memoryInputInteger(request.limit, this.config.defaultRecallLimit, 1, 50);
1702
1825
  const qualityContext = {
@@ -1755,7 +1878,8 @@ var MemorySpacesService = class {
1755
1878
  const hints = [];
1756
1879
  for (const [bodyOrder, { body, result }] of selectedBatches.entries()) {
1757
1880
  const scoreSemantics = this.providerFor(body).scoreSemantics;
1758
- candidates.push(...result.results.map((entry, index) => ({
1881
+ const entries = options.exclude === void 0 ? result.results : result.results.filter((entry) => !options.exclude.has(memoryKey(body.id, entry.id)));
1882
+ candidates.push(...entries.map((entry, index) => ({
1759
1883
  insight: this.annotate(entry, body),
1760
1884
  memoryBodyId: body.id,
1761
1885
  providerId: body.provider.id,
@@ -2013,41 +2137,208 @@ var MemorySpacesService = class {
2013
2137
  sources: batches.map((batch) => batch.source)
2014
2138
  };
2015
2139
  }
2140
+ /**
2141
+ * The entities of the active spaces, each counted once per memory that
2142
+ * carries it. With an entity, also the first page of those memories.
2143
+ */
2016
2144
  async entities(entity, limit, signal) {
2017
- const active = (await this.spaces(signal)).items.filter((body) => body.active);
2018
- const capable = active.filter((body) => body.provider.capabilities.entities);
2019
- const entityCounts = /* @__PURE__ */ new Map();
2020
- for (const body of capable) for (const item of body.stats?.topEntities ?? []) entityCounts.set(item.entity, (entityCounts.get(item.entity) ?? 0) + item.count);
2021
- const items = [...entityCounts].map(([name, count]) => ({
2022
- entity: name,
2023
- count
2024
- })).sort((left, right) => right.count - left.count);
2025
- const sources = active.map((body) => {
2026
- if (!body.provider.capabilities.entities) return readSource(body, "unsupported", "unsupported", 0, { hint: "This provider does not expose an entity index." });
2027
- if (!body.healthy) return readSource(body, "entities", "unavailable", 0, { hint: body.error ?? "Provider unavailable." });
2028
- const count = body.stats?.topEntities.length ?? 0;
2029
- return readSource(body, "entities", count === 0 ? "empty" : "ready", count);
2030
- });
2031
- const selected = entity?.trim() ?? "";
2032
- if (selected === "") return {
2033
- items,
2145
+ const selected = entity === void 0 ? "" : entityName(entity);
2146
+ const read = await this.readEntityIndexes(signal, 0);
2147
+ const { items } = mergeEntityCounts(read.indexes);
2148
+ const view = {
2149
+ items: items.slice(0, ENTITY_RAIL_LIMIT),
2034
2150
  insights: [],
2035
- sources
2151
+ sources: read.sources,
2152
+ total: items.length,
2153
+ complete: read.complete
2036
2154
  };
2037
- if (selected.length > 200) throw new Error("entity is too long (max 200 characters)");
2038
- const readableIds = capable.filter((body) => body.healthy).map((body) => body.id);
2155
+ if (selected === "") return view;
2156
+ const page = this.entityPage(read, selected, 0, memoryInputInteger(limit, 20, 1, 50));
2039
2157
  return {
2040
- items,
2041
- selected,
2042
- insights: readableIds.length === 0 ? [] : (await this.search({
2158
+ ...view,
2159
+ selected: page.entity,
2160
+ insights: page.items
2161
+ };
2162
+ }
2163
+ /** One page of the memories that carry an entity, by importance and then recency. */
2164
+ async entityMemories(entity, offset, limit, signal) {
2165
+ const selected = entityName(entity);
2166
+ if (selected === "") throw new Error("entity is required");
2167
+ const read = await this.readEntityIndexes(signal, ENTITY_SELECTION_STATUS_REUSE_MS);
2168
+ return this.entityPage(read, selected, memoryInputInteger(offset, 0, 0, 1e6), memoryInputInteger(limit, 50, 1, 200));
2169
+ }
2170
+ /**
2171
+ * What recall relates to an entity, without the memories that carry it.
2172
+ * Those are left out before the quality policy selects, so they cannot use up
2173
+ * its places and leave the related list empty.
2174
+ */
2175
+ async entityRelated(entity, limit, signal, view) {
2176
+ const selected = entityName(entity);
2177
+ if (selected === "") throw new Error("entity is required");
2178
+ const superseding = view === void 0 ? void 0 : new AbortController();
2179
+ if (view !== void 0) {
2180
+ this.entityRelatedViews.get(view)?.abort(/* @__PURE__ */ new Error("superseded by a newer entity selection"));
2181
+ this.entityRelatedViews.set(view, superseding);
2182
+ }
2183
+ const combined = superseding === void 0 ? signal : signal === void 0 ? superseding.signal : AbortSignal.any([signal, superseding.signal]);
2184
+ try {
2185
+ const read = await this.readEntityIndexes(combined, ENTITY_SELECTION_STATUS_REUSE_MS);
2186
+ const key = normalizeEntityKey(selected);
2187
+ const carrying = /* @__PURE__ */ new Set();
2188
+ for (const [bodyId, index] of read.byBody) for (const position of index.byKey.get(key) ?? []) carrying.add(memoryKey(bodyId, index.memories[position].id));
2189
+ const display = mergeEntityCounts(read.indexes).names.get(key) ?? selected;
2190
+ const readableIds = read.readable.map((body) => body.id);
2191
+ if (readableIds.length === 0) return {
2192
+ entity: display,
2193
+ items: [],
2194
+ sources: []
2195
+ };
2196
+ const result = await this.search({
2043
2197
  query: selected,
2044
2198
  intent: "ENTITY",
2045
2199
  limit: memoryInputInteger(limit, 20, 1, 50),
2046
2200
  memoryBodyIds: readableIds
2047
- }, signal)).results,
2048
- sources
2201
+ }, combined, { exclude: carrying });
2202
+ combined?.throwIfAborted();
2203
+ return {
2204
+ entity: display,
2205
+ items: result.results,
2206
+ sources: result.sources
2207
+ };
2208
+ } finally {
2209
+ if (view !== void 0 && this.entityRelatedViews.get(view) === superseding) this.entityRelatedViews.delete(view);
2210
+ }
2211
+ }
2212
+ entityPage(read, selected, offset, limit) {
2213
+ const key = normalizeEntityKey(selected);
2214
+ const memories = memoriesWithEntity(read.indexes, key);
2215
+ return {
2216
+ entity: mergeEntityCounts(read.indexes).names.get(key) ?? selected,
2217
+ total: memories.length,
2218
+ offset,
2219
+ items: memories.slice(offset, offset + limit),
2220
+ complete: read.complete,
2221
+ sources: read.sources
2049
2222
  };
2050
2223
  }
2224
+ /**
2225
+ * One entity index per active space that has an entity index, read
2226
+ * concurrently. A space keeps its index while its Provider statistics and
2227
+ * metadata stay the same; a write through this Source drops it.
2228
+ */
2229
+ async readEntityIndexes(signal, statusMaxAgeMs) {
2230
+ signal?.throwIfAborted();
2231
+ const active = this.memorySpaces.active();
2232
+ const capable = new Set(active.filter((body) => body.provider.capabilities.entities).map((body) => body.id));
2233
+ for (const id of this.entityIndexCache.keys()) if (!capable.has(id)) this.entityIndexCache.delete(id);
2234
+ const reads = await Promise.all(active.map(async (body) => {
2235
+ if (!body.provider.capabilities.entities) return {
2236
+ body,
2237
+ recall: false,
2238
+ source: readSource(body, "unsupported", "unsupported", 0, { hint: "This provider does not expose an entity index." })
2239
+ };
2240
+ const status = await this.entitySpaceStatus(body, statusMaxAgeMs);
2241
+ if (!status.healthy) return {
2242
+ body,
2243
+ recall: false,
2244
+ source: readSource(body, "entities", "unavailable", 0, { hint: status.error ?? "Provider unavailable." })
2245
+ };
2246
+ const recall = body.provider.capabilities.search;
2247
+ if (this.providerFor(body).entityIndex === void 0 && !body.provider.capabilities.browse) return {
2248
+ body,
2249
+ recall,
2250
+ source: readSource(body, "query-only", "query-required", 0, { hint: "This provider can only be queried; its memories appear among related memories." })
2251
+ };
2252
+ try {
2253
+ const index = await this.entityIndexFor(body, status);
2254
+ const options = {
2255
+ memoryCount: index.memoryCount,
2256
+ complete: index.complete,
2257
+ ...index.complete ? {} : { hint: "The Provider indexed only part of this space." }
2258
+ };
2259
+ return {
2260
+ body,
2261
+ index,
2262
+ recall,
2263
+ source: readSource(body, "entities", index.byKey.size === 0 ? "empty" : "ready", index.byKey.size, options)
2264
+ };
2265
+ } catch (error) {
2266
+ return {
2267
+ body,
2268
+ recall: false,
2269
+ source: readSource(body, "entities", "unavailable", 0, { hint: error instanceof Error ? error.message : String(error) })
2270
+ };
2271
+ }
2272
+ }));
2273
+ signal?.throwIfAborted();
2274
+ const byBody = /* @__PURE__ */ new Map();
2275
+ for (const read of reads) if (read.index !== void 0) byBody.set(read.body.id, read.index);
2276
+ const indexes = [...byBody.values()];
2277
+ return {
2278
+ byBody,
2279
+ indexes,
2280
+ readable: reads.filter((read) => read.recall).map((read) => read.body),
2281
+ sources: reads.map((read) => read.source),
2282
+ complete: indexes.every((index) => index.complete)
2283
+ };
2284
+ }
2285
+ /** Provider health for the entity reads: a read in flight is shared, a finished one reused for less than maxAgeMs. */
2286
+ entitySpaceStatus(body, maxAgeMs) {
2287
+ const recent = this.entityStatusCache.get(body.id);
2288
+ if (recent !== void 0 && (recent.settledAt === void 0 || Date.now() - recent.settledAt < maxAgeMs)) return recent.status;
2289
+ const entry = {
2290
+ settledAt: void 0,
2291
+ status: Promise.resolve(void 0)
2292
+ };
2293
+ entry.status = this.providerFor(body).status(body).catch((error) => ({
2294
+ healthy: false,
2295
+ error: error instanceof Error ? error.message : String(error)
2296
+ })).then((status) => {
2297
+ entry.settledAt = Date.now();
2298
+ return status;
2299
+ });
2300
+ this.entityStatusCache.set(body.id, entry);
2301
+ return entry.status;
2302
+ }
2303
+ entityIndexFor(body, status) {
2304
+ const fingerprint = entityIndexFingerprint(body, status);
2305
+ const cached = this.entityIndexCache.get(body.id);
2306
+ if (cached !== void 0 && cached.fingerprint === fingerprint) {
2307
+ if (fingerprint !== void 0 || cached.settledAt === void 0 || Date.now() - cached.settledAt < ENTITY_INDEX_UNCHECKED_REUSE_MS) return cached.index;
2308
+ }
2309
+ const entry = {
2310
+ fingerprint,
2311
+ settledAt: void 0,
2312
+ index: Promise.resolve(void 0)
2313
+ };
2314
+ entry.index = this.buildEntityIndex(body).then((index) => {
2315
+ entry.settledAt = Date.now();
2316
+ return index;
2317
+ }, (error) => {
2318
+ if (this.entityIndexCache.get(body.id) === entry) this.entityIndexCache.delete(body.id);
2319
+ throw error;
2320
+ });
2321
+ this.entityIndexCache.set(body.id, entry);
2322
+ return entry.index;
2323
+ }
2324
+ async buildEntityIndex(body) {
2325
+ const provider = this.providerFor(body);
2326
+ if (provider.entityIndex !== void 0) {
2327
+ const owned = await provider.entityIndex(body);
2328
+ return buildSpaceEntityIndex(owned.memories.map((memory) => this.entityMemory(memory, body)), owned.memories.length, owned.complete);
2329
+ }
2330
+ const listed = await provider.list(body, { limit: ENTITY_INDEX_LIST_LIMIT });
2331
+ return buildSpaceEntityIndex(listed.map((memory) => this.entityMemory(memory, body)), listed.length, listed.length < ENTITY_INDEX_LIST_LIMIT);
2332
+ }
2333
+ /** A listed memory, not a query result: no relevance fields. */
2334
+ entityMemory(memory, body) {
2335
+ const { score: _score, normalizedScore: _normalized, relevanceTier: _tier, federatedScore: _federated, confidence: _confidence, intent: _intent, matchedVia: _matchedVia, depth: _depth, edgeType: _edgeType, ...listed } = memory;
2336
+ return this.annotate(listed, body);
2337
+ }
2338
+ invalidateEntityIndex(memoryBodyId) {
2339
+ this.entityIndexCache.delete(memoryBodyId);
2340
+ this.entityStatusCache.delete(memoryBodyId);
2341
+ }
2051
2342
  async remember(request, signal) {
2052
2343
  this.assertWritable();
2053
2344
  const prepared = this.prepareRemember(request);
@@ -2378,6 +2669,7 @@ var MemorySpacesService = class {
2378
2669
  };
2379
2670
  }
2380
2671
  activateAfterWrite(body, providerChanged) {
2672
+ this.invalidateEntityIndex(body.id);
2381
2673
  if (!providerChanged) return;
2382
2674
  if (!body.active) this.memorySpaces.setActive(body.id, true);
2383
2675
  else this.memorySpaces.touch(body.id);
@@ -2774,6 +3066,8 @@ async function manageMemorySpaces(service, request) {
2774
3066
  ...memoryInputStringArray(input.memoryBodyIds, "memoryBodyIds", 1e4) === void 0 ? {} : { memoryBodyIds: memoryInputStringArray(input.memoryBodyIds, "memoryBodyIds", 1e4) }
2775
3067
  }, request.signal));
2776
3068
  case "entities": return managementResult(service, await service.entities(memoryInputText(input.entity, "entity", 500, false), input.limit === void 0 ? void 0 : memoryInputInteger(input.limit, 100, 1, 1e4), request.signal));
3069
+ case "entity-memories": return managementResult(service, await service.entityMemories(memoryInputText(input.entity, "entity", 500), input.offset === void 0 ? void 0 : memoryInputInteger(input.offset, 0, 0, 1e6), input.limit === void 0 ? void 0 : memoryInputInteger(input.limit, 50, 1, 200), request.signal));
3070
+ case "entity-related": return managementResult(service, await service.entityRelated(memoryInputText(input.entity, "entity", 500), input.limit === void 0 ? void 0 : memoryInputInteger(input.limit, 20, 1, 50), request.signal, memoryInputText(input.view, "view", 200, false)));
2777
3071
  case "search": return managementResult(service, await service.search({
2778
3072
  query: memoryInputText(input.query, "query", 2e3),
2779
3073
  ...memoryInputText(input.mode, "mode", 20, false) === void 0 ? {} : { mode: memoryInputText(input.mode, "mode", 20, false) },
@@ -1,5 +1,5 @@
1
1
  import { CATEGORIES, Category, EDGE_TYPES, EdgeType, INTENTS, Insight, Intent, JsonValue, MemoryBody, MemoryBodyProvider, MemoryBodyStats, MemoryGraphEdge, MemoryGraphNode, MemoryGraphSnapshot, MemoryListRequest, MemoryProviderCapabilities, MemoryProviderConfigField, MemoryProviderConfigOption, MemoryProviderConnection, MemoryProviderConnectionValue, MemoryProviderDescriptor, MemoryProviderIcon, MemoryProviderId, MemorySpace, MemorySpaceProvider, MemorySpaceStats, OpenVikingBodyConnection, OpenVikingSpaceConnection, RememberRequest, SOURCES, SearchRequest, Source } from "./contracts.js";
2
- import { C as ProviderSpaceStatus, S as ProviderSearchResult, _ as MemorySpaceNativeRunner, a as MemorySpaceProviderHost, b as ProviderMemorySpace, c as MemorySpaceProviderRuntimeContext, d as defineMemorySpaceProviderDefinition, f as MemoryProviderAdapter, g as MemorySpaceNativeRunOptions, h as MemorySpaceAuthority, i as MemorySpaceProviderEntry, l as MemorySpaceProviderScoreSemantics, m as MemoryProviderScoreSemantics, n as MemorySpaceProviderDefinition, o as MemorySpaceProviderManifest, p as MemoryProviderAdapterFactoryContext, r as MemorySpaceProviderDisposer, s as MemorySpaceProviderModule, t as MEMORY_SPACE_PROVIDER_API_VERSION, u as defineMemorySpaceProvider, v as NORMALIZED_RELEVANCE_SCORE, x as ProviderScoreSemantics, y as ProviderBodyStatus } from "./definitions-DwiEZSE_.js";
2
+ import { C as ProviderSearchResult, S as ProviderScoreSemantics, _ as MemorySpaceNativeRunner, a as MemorySpaceProviderHost, b as ProviderEntityIndex, c as MemorySpaceProviderRuntimeContext, d as defineMemorySpaceProviderDefinition, f as MemoryProviderAdapter, g as MemorySpaceNativeRunOptions, h as MemorySpaceAuthority, i as MemorySpaceProviderEntry, l as MemorySpaceProviderScoreSemantics, m as MemoryProviderScoreSemantics, n as MemorySpaceProviderDefinition, o as MemorySpaceProviderManifest, p as MemoryProviderAdapterFactoryContext, r as MemorySpaceProviderDisposer, s as MemorySpaceProviderModule, t as MEMORY_SPACE_PROVIDER_API_VERSION, u as defineMemorySpaceProvider, v as NORMALIZED_RELEVANCE_SCORE, w as ProviderSpaceStatus, x as ProviderMemorySpace, y as ProviderBodyStatus } from "./definitions-BcYzE092.js";
3
3
  //#region src/providers/http.d.ts
4
4
  interface HttpProviderOptions {
5
5
  label?: string;
@@ -60,4 +60,4 @@ declare const DEFAULT_MAX_OUTPUT_BYTES: number;
60
60
  /** Spawn without a shell, with bounded output and cooperative cancellation. */
61
61
  declare const runProcess: ProcessRunner;
62
62
  //#endregion
63
- export { CATEGORIES, type Category, DEFAULT_MAX_OUTPUT_BYTES, EDGE_TYPES, type EdgeType, HttpMemoryProvider, HttpProviderOptions, INTENTS, type Insight, type Intent, JsonRequestOptions, type JsonValue, MEMORY_SPACE_PROVIDER_API_VERSION, type MemoryBody, type MemoryBodyProvider, type MemoryBodyStats, type MemoryGraphEdge, type MemoryGraphNode, type MemoryGraphSnapshot, type MemoryListRequest, MemoryProviderAdapter, MemoryProviderAdapterFactoryContext, type MemoryProviderCapabilities, type MemoryProviderConfigField, type MemoryProviderConfigOption, type MemoryProviderConnection, type MemoryProviderConnectionValue, type MemoryProviderDescriptor, type MemoryProviderIcon, type MemoryProviderId, MemoryProviderScoreSemantics, type MemorySpace, MemorySpaceAuthority, MemorySpaceNativeRunOptions, MemorySpaceNativeRunner, type MemorySpaceProvider, type MemorySpaceProviderDefinition, type MemorySpaceProviderDisposer, type MemorySpaceProviderEntry, type MemorySpaceProviderHost, type MemorySpaceProviderManifest, type MemorySpaceProviderModule, type MemorySpaceProviderRuntimeContext, type MemorySpaceProviderScoreSemantics, type MemorySpaceStats, NORMALIZED_RELEVANCE_SCORE, type OpenVikingBodyConnection, type OpenVikingSpaceConnection, ProcessError, ProcessFailureReason, ProcessOptions, ProcessResult, ProcessRunner, ProviderBodyStatus, ProviderMemorySpace, ProviderScoreSemantics, ProviderSearchResult, ProviderSpaceStatus, type RememberRequest, SOURCES, type SearchRequest, type Source, defineMemorySpaceProvider, defineMemorySpaceProviderDefinition, firstArray, jsonArray, jsonNumber, jsonObject, jsonString, runProcess };
63
+ export { CATEGORIES, type Category, DEFAULT_MAX_OUTPUT_BYTES, EDGE_TYPES, type EdgeType, HttpMemoryProvider, HttpProviderOptions, INTENTS, type Insight, type Intent, JsonRequestOptions, type JsonValue, MEMORY_SPACE_PROVIDER_API_VERSION, type MemoryBody, type MemoryBodyProvider, type MemoryBodyStats, type MemoryGraphEdge, type MemoryGraphNode, type MemoryGraphSnapshot, type MemoryListRequest, MemoryProviderAdapter, MemoryProviderAdapterFactoryContext, type MemoryProviderCapabilities, type MemoryProviderConfigField, type MemoryProviderConfigOption, type MemoryProviderConnection, type MemoryProviderConnectionValue, type MemoryProviderDescriptor, type MemoryProviderIcon, type MemoryProviderId, MemoryProviderScoreSemantics, type MemorySpace, MemorySpaceAuthority, MemorySpaceNativeRunOptions, MemorySpaceNativeRunner, type MemorySpaceProvider, type MemorySpaceProviderDefinition, type MemorySpaceProviderDisposer, type MemorySpaceProviderEntry, type MemorySpaceProviderHost, type MemorySpaceProviderManifest, type MemorySpaceProviderModule, type MemorySpaceProviderRuntimeContext, type MemorySpaceProviderScoreSemantics, type MemorySpaceStats, NORMALIZED_RELEVANCE_SCORE, type OpenVikingBodyConnection, type OpenVikingSpaceConnection, ProcessError, ProcessFailureReason, ProcessOptions, ProcessResult, ProcessRunner, ProviderBodyStatus, ProviderEntityIndex, ProviderMemorySpace, ProviderScoreSemantics, ProviderSearchResult, ProviderSpaceStatus, type RememberRequest, SOURCES, type SearchRequest, type Source, defineMemorySpaceProvider, defineMemorySpaceProviderDefinition, firstArray, jsonArray, jsonNumber, jsonObject, jsonString, runProcess };
package/lib/testing.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { MemoryProviderConnection, MemoryProviderDescriptor, MemorySpace } from "./contracts.js";
2
- import { f as MemoryProviderAdapter, h as MemorySpaceAuthority, o as MemorySpaceProviderManifest, p as MemoryProviderAdapterFactoryContext, s as MemorySpaceProviderModule } from "./definitions-DwiEZSE_.js";
2
+ import { f as MemoryProviderAdapter, h as MemorySpaceAuthority, o as MemorySpaceProviderManifest, p as MemoryProviderAdapterFactoryContext, s as MemorySpaceProviderModule } from "./definitions-BcYzE092.js";
3
3
  //#region src/testing.d.ts
4
4
  interface MemorySpaceProviderTest {
5
5
  readonly registered: boolean;
@@ -1,4 +1,4 @@
1
- import type { CreateMemorySpaceRequest, EntityView, Insight, MemorySpace, MemorySpaceView, MemorySpaceMetadataMaintenanceResult, MemorySpaceCatalog, MemoryGraphSnapshot, MemoryListRequest, MemoryListView, MemoryReadSource, RememberRequest, SearchRequest, UpdateMemorySpaceRequest } from '../contracts.ts';
1
+ import type { CreateMemorySpaceRequest, EntityMemoriesView, EntityRelatedView, EntityView, Insight, MemorySpace, MemorySpaceView, MemorySpaceMetadataMaintenanceResult, MemorySpaceCatalog, MemoryGraphSnapshot, MemoryListRequest, MemoryListView, MemoryReadSource, RememberRequest, SearchRequest, UpdateMemorySpaceRequest } from '../contracts.ts';
2
2
  /**
3
3
  * Source-owned structural page API; the default bundle may supply agent-assisted callbacks.
4
4
  * body/bodies method and wire-field spellings remain compatible with existing
@@ -10,6 +10,10 @@ export interface MemorySpacesPageClient {
10
10
  graph(memoryBodyIds?: string[]): Promise<MemoryGraphSnapshot>;
11
11
  list(request?: MemoryListRequest): Promise<MemoryListView>;
12
12
  entities(entity?: string, limit?: number): Promise<EntityView>;
13
+ /** Optional for page clients written against an older Source; the Entities page then lists entities(entity) only. */
14
+ entityMemories?(entity: string, offset?: number, limit?: number): Promise<EntityMemoriesView>;
15
+ /** view: one id per page view; its next selection cancels the related read it is still waiting for. */
16
+ entityRelated?(entity: string, limit?: number, view?: string): Promise<EntityRelatedView>;
13
17
  search(request: SearchRequest): Promise<SearchResponse>;
14
18
  agentSearch(request: SearchRequest): Promise<AgentSearchResponse>;
15
19
  related(id: string, memoryBodyId?: string): Promise<Insight[]>;