@melandlabs/memory-store 0.3.1 → 1.0.0

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.
@@ -1,12 +1,15 @@
1
1
  #!/usr/bin/env node
2
- import { H as UnifiedSearchDeps } from '../config-2Q092MUz.js';
2
+ import { U as UnifiedSearchDeps } from '../config-CnbqSek5.js';
3
+ import '@melandlabs/memory-consolidation';
4
+ import '@melandlabs/contracts/peer';
5
+ import '@melandlabs/contracts';
3
6
 
4
7
  /**
5
8
  * Shared argv parsing + `unified.*` wiring for the memory-store CLI bins.
6
9
  *
7
10
  * Both `cli-http.ts` (the HTTP daemon) and `cli-mcp.ts` (the MCP daemon)
8
11
  * take the same `--embedding-provider` / `--*-backend` flag surface —
9
- * the MCP server exposes the same `searchUnifiedMemory` tool the HTTP
12
+ * the MCP server exposes the same `memory.search` tool the HTTP
10
13
  * `/v1/search` route does, so they must speak the same config. This
11
14
  * module owns that surface so the two bins stay in lock-step.
12
15
  *
@@ -5,6 +5,7 @@ import { getOpenContextPath } from '@melandlabs/env-config';
5
5
  import { SQLiteRawMessageManager } from '@melandlabs/sqlite';
6
6
  import '@melandlabs/ai/memory';
7
7
  import '@melandlabs/rag';
8
+ import '@melandlabs/contracts';
8
9
 
9
10
  // src/storage/postgres-raw-message-factory.ts
10
11
  var factory = null;
@@ -14,6 +15,8 @@ async function resolvePostgresFactory(env) {
14
15
  function hasPostgresFactory() {
15
16
  return factory !== null;
16
17
  }
18
+
19
+ // src/storage/chroma-memory-index.ts
17
20
  var RAW_VECTOR_BACKEND_ENV_KEYS = [
18
21
  "RAW_MESSAGE_VECTOR_STORE_BACKEND",
19
22
  "MEMORY_VECTOR_STORE_BACKEND",
@@ -1,5 +1,6 @@
1
1
  import { RawMessage } from '../contracts.js';
2
2
  import '@melandlabs/ai/memory';
3
+ import '@melandlabs/contracts';
3
4
 
4
5
  /**
5
6
  * Chroma-backed raw-message + insight vector index.
@@ -1,9 +1,8 @@
1
1
  import { buildMemoryRecordEmbeddingDocument } from '@melandlabs/ai/memory';
2
2
  import { ChromaVectorStore } from '@melandlabs/rag';
3
+ import '@melandlabs/contracts';
3
4
 
4
5
  // src/storage/chroma-memory-index.ts
5
-
6
- // src/contracts.ts
7
6
  function normalizeTimestampToMs(value) {
8
7
  if (!Number.isFinite(value)) {
9
8
  return 0;
@@ -1,4 +1,7 @@
1
- import { i as MemoryStoreEnv } from '../config-2Q092MUz.js';
1
+ import { a as MemoryStoreEnv } from '../config-CnbqSek5.js';
2
+ import '@melandlabs/memory-consolidation';
3
+ import '@melandlabs/contracts/peer';
4
+ import '@melandlabs/contracts';
2
5
 
3
6
  /**
4
7
  * Lazy registration slot for the host's Postgres-backed raw message
@@ -1,5 +1,8 @@
1
- import { RawMessageStorageManager } from '@melandlabs/indexeddb/storage';
2
- import { i as MemoryStoreEnv, M as MemoryStoreConfig } from '../config-2Q092MUz.js';
1
+ import { RawMessageStorageManager } from '@melandlabs/indexeddb';
2
+ import { a as MemoryStoreEnv, M as MemoryStoreConfig } from '../config-CnbqSek5.js';
3
+ import '@melandlabs/memory-consolidation';
4
+ import '@melandlabs/contracts/peer';
5
+ import '@melandlabs/contracts';
3
6
 
4
7
  /**
5
8
  * Top-level raw-message store facade.
@@ -4,6 +4,7 @@ import { getOpenContextPath } from '@melandlabs/env-config';
4
4
  import { SQLiteRawMessageManager } from '@melandlabs/sqlite';
5
5
  import '@melandlabs/ai/memory';
6
6
  import '@melandlabs/rag';
7
+ import '@melandlabs/contracts';
7
8
 
8
9
  // src/storage/postgres-raw-message-factory.ts
9
10
  var factory = null;
@@ -13,6 +14,8 @@ async function resolvePostgresFactory(env) {
13
14
  function hasPostgresFactory() {
14
15
  return factory !== null;
15
16
  }
17
+
18
+ // src/storage/chroma-memory-index.ts
16
19
  var RAW_VECTOR_BACKEND_ENV_KEYS = [
17
20
  "RAW_MESSAGE_VECTOR_STORE_BACKEND",
18
21
  "MEMORY_VECTOR_STORE_BACKEND",
@@ -1,5 +1,8 @@
1
1
  import { SQLiteRawMessageManager } from '@melandlabs/sqlite';
2
- import { i as MemoryStoreEnv } from '../config-2Q092MUz.js';
2
+ import { a as MemoryStoreEnv } from '../config-CnbqSek5.js';
3
+ import '@melandlabs/memory-consolidation';
4
+ import '@melandlabs/contracts/peer';
5
+ import '@melandlabs/contracts';
3
6
 
4
7
  /**
5
8
  * SQLite-backed raw message store.
@@ -45,6 +48,7 @@ declare function lexicalSearchRawMessages(input: {
45
48
  includeArchived?: boolean;
46
49
  platform?: string;
47
50
  botId?: string;
51
+ factTypes?: Array<"world" | "experience" | "mental_model">;
48
52
  }): Promise<unknown[]>;
49
53
 
50
54
  export { __resetSQLiteRawMessageManagerForTests, closeSQLiteRawMessageManager, getSQLiteRawMessageManager, isSQLiteRawMessageStorageAvailable, lexicalSearchRawMessages, resolveSQLiteRawMessageDbPath };
@@ -4,8 +4,11 @@ import { getOpenContextPath } from '@melandlabs/env-config';
4
4
  import { SQLiteRawMessageManager } from '@melandlabs/sqlite';
5
5
  import '@melandlabs/ai/memory';
6
6
  import '@melandlabs/rag';
7
+ import '@melandlabs/contracts';
7
8
 
8
9
  // src/storage/sqlite-raw-message-store.ts
10
+
11
+ // src/storage/chroma-memory-index.ts
9
12
  var RAW_VECTOR_BACKEND_ENV_KEYS = [
10
13
  "RAW_MESSAGE_VECTOR_STORE_BACKEND",
11
14
  "MEMORY_VECTOR_STORE_BACKEND",
@@ -1,5 +1,8 @@
1
1
  import { VectorSearchResult } from '@melandlabs/rag/vector-service';
2
- import { i as MemoryStoreEnv } from '../config-2Q092MUz.js';
2
+ import { a as MemoryStoreEnv } from '../config-CnbqSek5.js';
3
+ import '@melandlabs/memory-consolidation';
4
+ import '@melandlabs/contracts/peer';
5
+ import '@melandlabs/contracts';
3
6
 
4
7
  /**
5
8
  * SQLite-vec-backed raw-message + insight vector index.
@@ -4,6 +4,7 @@ import { getOpenContextPath } from '@melandlabs/env-config';
4
4
  import '@melandlabs/sqlite';
5
5
  import '@melandlabs/ai/memory';
6
6
  import '@melandlabs/rag';
7
+ import '@melandlabs/contracts';
7
8
 
8
9
  // src/storage/sqlite-raw-message-store.ts
9
10
 
@@ -0,0 +1,122 @@
1
+ import { S as SearchTier, b as UnifiedMemorySearchWarning, c as SearchEvidence, U as UnifiedSearchDeps, d as SearchInput, e as SearchOutput, f as UnifiedMemorySearchInput, g as UnifiedMemorySearchOutput, h as UnifiedMemorySearchResult } from './config-CnbqSek5.js';
2
+ import { MemoryStorageAdapter } from '@melandlabs/ai/memory';
3
+ import { Peer } from '@melandlabs/contracts/peer';
4
+ import { OwnerScope, MemoryConsolidationPlan, ReflectApplyClusterKeyFn, MemoryStorageAdapterLike, MemoryGraphStoreWithOperationHistory, MemoryGraphUpdateResult } from '@melandlabs/memory-consolidation';
5
+
6
+ /**
7
+ * `applyReflectedPlan` — agentic write-back facade.
8
+ *
9
+ * Composes the read-only `search({ synthesize })` evidence pipeline with
10
+ * the `applyReflectedConsolidationPlan` write-side so a single call
11
+ * gathers evidence (raw + summaries + insights + knowledge), vets the
12
+ * plan with the LLM (optional), and persists the result to the graph
13
+ * store + storage.
14
+ *
15
+ * Behaviour parity with `search({ synthesize: true })`:
16
+ * - Reuses the same gather-evidence pipeline so the answer + evidence
17
+ * are identical to a read-only search call.
18
+ * - Honours `peerFilter` via the same scope check used by the unified
19
+ * read pipeline.
20
+ * - LLM `complete` is the same `deps.reasoning.complete` the read-only
21
+ * path uses — no new injection point.
22
+ *
23
+ * Write path:
24
+ * - When `graphStore` is set (either passed in or attached via
25
+ * `attachMemoryGraphStore`), persists the graph plan via
26
+ * `MemoryGraphStoreWithOperationHistory.persistPlan`.
27
+ * - Always runs `storage.deprecateRecords` for `deprecate` entries — the
28
+ * deprecation chain is the critical path, so it runs even when the
29
+ * graph store is missing (with a `reflect_apply_graph_store_not_configured`
30
+ * warning).
31
+ */
32
+
33
+ interface ApplyConsolidateInput {
34
+ userId: string;
35
+ query: string;
36
+ ownerScope: OwnerScope;
37
+ botIds?: string[];
38
+ dateFrom?: string;
39
+ dateTo?: string;
40
+ tiers?: ReadonlyArray<SearchTier>;
41
+ limit?: number;
42
+ threshold?: number;
43
+ plan?: MemoryConsolidationPlan;
44
+ dryRun?: boolean;
45
+ expectedVersion?: string;
46
+ llmPlanReview?: {
47
+ maxTokens?: number;
48
+ };
49
+ authToken?: string;
50
+ peerFilter?: ReadonlyArray<Peer>;
51
+ /**
52
+ * Cluster-key selector forwarded to `buildMemoryConsolidationPlan`.
53
+ * When omitted, callers should pass a pre-built `plan`.
54
+ */
55
+ getClusterKey?: ReflectApplyClusterKeyFn;
56
+ /**
57
+ * Optional storage adapter — falls back to `store.raw` when wired up by
58
+ * `createMemoryStore`. Required when no `graphStore` is attached and the
59
+ * caller still wants `deprecateRecords` writes.
60
+ */
61
+ storage?: MemoryStorageAdapterLike;
62
+ graphStore?: MemoryGraphStoreWithOperationHistory;
63
+ }
64
+ interface ApplyConsolidateOutput {
65
+ answer: string;
66
+ plan: MemoryConsolidationPlan;
67
+ persistenceResult?: MemoryGraphUpdateResult;
68
+ deprecationCounts?: Array<{
69
+ supersededBySummaryId: string;
70
+ count: number;
71
+ }>;
72
+ warnings: UnifiedMemorySearchWarning[];
73
+ applied: boolean;
74
+ evidence: SearchEvidence[];
75
+ }
76
+ interface MemoryStoreLike {
77
+ graphStore?: MemoryGraphStoreWithOperationHistory;
78
+ storage?: MemoryStorageAdapterLike | MemoryStorageAdapter;
79
+ }
80
+ declare function applyReflectedPlan(deps: UnifiedSearchDeps, store: MemoryStoreLike, input: ApplyConsolidateInput, _logger: Pick<Console, "log" | "warn" | "error">): Promise<ApplyConsolidateOutput>;
81
+
82
+ /**
83
+ * Unified semantic search facade.
84
+ *
85
+ * Cross-source search over raw messages (always), insights, and
86
+ * uploaded knowledge documents. The host wires up the cross-domain
87
+ * dependencies via `UnifiedSearchDeps` so this module stays
88
+ * framework-agnostic.
89
+ *
90
+ * The public entry point is `search(input)` — a single method. Set
91
+ * `synthesize: true` to opt into the LLM synthesis step.
92
+ */
93
+
94
+ interface UnifiedSearch {
95
+ /**
96
+ * Single unified read entry point. Set `synthesize: true` to opt into
97
+ * LLM synthesis.
98
+ */
99
+ search(input: SearchInput): Promise<SearchOutput>;
100
+ /**
101
+ * @deprecated Use `search(input)` instead. Forwarding shim kept for
102
+ * one release window.
103
+ */
104
+ searchUnifiedMemory(input: UnifiedMemorySearchInput): Promise<UnifiedMemorySearchOutput>;
105
+ /**
106
+ * @deprecated Use `search({ ...input, sources: ["memory"] })` and
107
+ * read `.results` instead.
108
+ */
109
+ searchRawMemorySemantically(input: UnifiedMemorySearchInput): Promise<UnifiedMemorySearchResult[]>;
110
+ /**
111
+ * Agentic write-back: runs the same evidence pipeline as `search`,
112
+ * then builds a memory-consolidation plan, optionally asks the LLM
113
+ * to veto unsafe entries, and persists via the attached graph store
114
+ * (when present) + soft-deprecates superseded records via the storage
115
+ * adapter. See `./apply-reflect.ts` for the contract and degradation
116
+ * rules.
117
+ */
118
+ consolidate(input: ApplyConsolidateInput): Promise<ApplyConsolidateOutput>;
119
+ }
120
+ declare function createUnifiedSearch(deps?: UnifiedSearchDeps): UnifiedSearch;
121
+
122
+ export { type ApplyConsolidateInput as A, type UnifiedSearch as U, type ApplyConsolidateOutput as a, applyReflectedPlan as b, createUnifiedSearch as c };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@melandlabs/memory-store",
3
- "version": "0.3.1",
3
+ "version": "1.0.0",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist",
@@ -60,15 +60,18 @@
60
60
  "@modelcontextprotocol/sdk": "^1.25.3",
61
61
  "hono": "^4.6.14",
62
62
  "zod": "^4.3.6",
63
- "@melandlabs/ai": "0.3.1",
63
+ "@melandlabs/ai": "0.5.0",
64
+ "@melandlabs/memory-consolidation": "0.5.0",
64
65
  "@melandlabs/env-config": "0.4.0",
66
+ "@melandlabs/contracts": "0.5.0",
67
+ "@melandlabs/sqlite": "0.5.0",
68
+ "@melandlabs/vsa": "0.3.0",
65
69
  "@melandlabs/rag": "0.2.2",
66
- "@melandlabs/sqlite": "0.3.0",
67
70
  "@melandlabs/shared": "0.3.0"
68
71
  },
69
72
  "peerDependencies": {
70
- "@melandlabs/ai-rag": "0.2.4",
71
- "@melandlabs/indexeddb": "0.3.0"
73
+ "@melandlabs/ai-rag": "0.2.6",
74
+ "@melandlabs/indexeddb": "0.5.0"
72
75
  },
73
76
  "peerDependenciesMeta": {
74
77
  "@melandlabs/ai-rag": {
@@ -81,7 +84,7 @@
81
84
  "devDependencies": {
82
85
  "@types/node": "^22.13.10",
83
86
  "typescript": "^5.6.3",
84
- "@melandlabs/ai-rag": "0.2.4",
87
+ "@melandlabs/ai-rag": "0.2.6",
85
88
  "@melandlabs/config": "0.3.0"
86
89
  },
87
90
  "scripts": {