mentedb 0.3.1 → 0.7.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.
package/README.md CHANGED
@@ -96,7 +96,9 @@ const next = tracker.predictNextTopics();
96
96
  | `recall(query)` | Recall memories via an MQL query. Returns `RecallResult`. |
97
97
  | `search(embedding, k)` | Vector similarity search. Returns `SearchResult[]`. |
98
98
  | `relate(source, target, edgeType?, weight?)` | Create a typed edge between two memories. |
99
+ | `processTurn(userMessage, assistantResponse?, turnId?, projectContext?, agentId?)` | Process a conversation turn through the full cognitive pipeline. Returns context, actions, sentiment, predictions, and more. |
99
100
  | `forget(memoryId)` | Remove a memory by ID. |
101
+ | `ingest(conversation, provider?, agentId?)` | Extract and store memories from a conversation via LLM. |
100
102
  | `close()` | Flush and close the database. |
101
103
 
102
104
  ### `CognitionStream`
Binary file
Binary file
Binary file
Binary file
@@ -0,0 +1,56 @@
1
+ import { EdgeType, type StoreOptions, type RecallResult, type SearchResult } from './types';
2
+ /**
3
+ * MenteDB client. Wraps the native Rust database engine and exposes a
4
+ * TypeScript-friendly API for storing, recalling, searching, relating, and
5
+ * forgetting memories.
6
+ */
7
+ export declare class MenteDB {
8
+ private native;
9
+ constructor(dataDir?: string);
10
+ /** Store a memory and return its UUID. */
11
+ store(options: StoreOptions): string;
12
+ /** Recall memories using an MQL query string. */
13
+ recall(query: string): RecallResult;
14
+ /** Vector similarity search returning top-k results. */
15
+ search(embedding: number[], k?: number): SearchResult[];
16
+ /** Create a typed, weighted edge between two memories. */
17
+ relate(source: string, target: string, edgeType?: EdgeType, weight?: number): void;
18
+ /** Remove a memory by ID. */
19
+ forget(memoryId: string): void;
20
+ /** Flush all data and close the database. */
21
+ close(): void;
22
+ }
23
+ /**
24
+ * Monitors an LLM token stream for contradictions, forgotten facts,
25
+ * corrections, and reinforcements.
26
+ */
27
+ export declare class CognitionStream {
28
+ private native;
29
+ constructor(bufferSize?: number);
30
+ /** Push a token into the stream buffer. */
31
+ feedToken(token: string): void;
32
+ /** Drain the accumulated buffer and return its content. */
33
+ drainBuffer(): string;
34
+ }
35
+ /**
36
+ * Tracks the reasoning arc of a conversation and predicts next topics.
37
+ */
38
+ export declare class TrajectoryTracker {
39
+ private native;
40
+ constructor(maxTurns?: number);
41
+ /**
42
+ * Record a conversation turn.
43
+ *
44
+ * `decisionState` accepts one of:
45
+ * - `"investigating"`
46
+ * - `"interrupted"`
47
+ * - `"completed"`
48
+ * - `"narrowed:<choice>"`
49
+ * - `"decided:<decision>"`
50
+ */
51
+ recordTurn(topic: string, decisionState: string, openQuestions?: string[]): void;
52
+ /** Get a resume context string describing the current trajectory. */
53
+ getResumeContext(): string | null;
54
+ /** Predict the next likely topics based on trajectory. */
55
+ predictNextTopics(): string[];
56
+ }
package/npm/client.js ADDED
@@ -0,0 +1,150 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.TrajectoryTracker = exports.CognitionStream = exports.MenteDB = void 0;
37
+ const types_1 = require("./types");
38
+ const os = __importStar(require("os"));
39
+ const path = __importStar(require("path"));
40
+ const PLATFORM_TRIPLES = {
41
+ 'linux-x64': 'linux-x64-gnu',
42
+ 'darwin-arm64': 'darwin-arm64',
43
+ 'darwin-x64': 'darwin-x64',
44
+ 'win32-x64': 'win32-x64-msvc',
45
+ };
46
+ function loadNativeBinding() {
47
+ const key = `${os.platform()}-${os.arch()}`;
48
+ const triple = PLATFORM_TRIPLES[key];
49
+ // Try platform-specific binary first (from CI cross-compile)
50
+ if (triple) {
51
+ try {
52
+ return require(path.join(__dirname, '..', `mentedb.${triple}.node`));
53
+ }
54
+ catch { }
55
+ }
56
+ // Fall back to unqualified binary (local `napi build --release`)
57
+ try {
58
+ return require(path.join(__dirname, '..', 'mentedb.node'));
59
+ }
60
+ catch { }
61
+ const supported = Object.keys(PLATFORM_TRIPLES).join(', ');
62
+ throw new Error(`No native binding found for ${key}. ` +
63
+ `Supported platforms: ${supported}. ` +
64
+ `Build locally with: cd sdks/typescript && npm run build`);
65
+ }
66
+ const nativeBinding = loadNativeBinding();
67
+ /**
68
+ * MenteDB client. Wraps the native Rust database engine and exposes a
69
+ * TypeScript-friendly API for storing, recalling, searching, relating, and
70
+ * forgetting memories.
71
+ */
72
+ class MenteDB {
73
+ constructor(dataDir = './mentedb-data') {
74
+ this.native = new nativeBinding.MenteDb(dataDir);
75
+ }
76
+ /** Store a memory and return its UUID. */
77
+ store(options) {
78
+ const { content, memoryType = types_1.MemoryType.Episodic, embedding = [], agentId, tags, } = options;
79
+ return this.native.store(content, memoryType, embedding, agentId, tags);
80
+ }
81
+ /** Recall memories using an MQL query string. */
82
+ recall(query) {
83
+ return this.native.recall(query);
84
+ }
85
+ /** Vector similarity search returning top-k results. */
86
+ search(embedding, k = 10) {
87
+ return this.native.search(embedding, k);
88
+ }
89
+ /** Create a typed, weighted edge between two memories. */
90
+ relate(source, target, edgeType = types_1.EdgeType.Related, weight = 1.0) {
91
+ this.native.relate(source, target, edgeType, weight);
92
+ }
93
+ /** Remove a memory by ID. */
94
+ forget(memoryId) {
95
+ this.native.forget(memoryId);
96
+ }
97
+ /** Flush all data and close the database. */
98
+ close() {
99
+ this.native.close();
100
+ }
101
+ }
102
+ exports.MenteDB = MenteDB;
103
+ /**
104
+ * Monitors an LLM token stream for contradictions, forgotten facts,
105
+ * corrections, and reinforcements.
106
+ */
107
+ class CognitionStream {
108
+ constructor(bufferSize = 1000) {
109
+ this.native = new nativeBinding.JsCognitionStream(bufferSize);
110
+ }
111
+ /** Push a token into the stream buffer. */
112
+ feedToken(token) {
113
+ this.native.feedToken(token);
114
+ }
115
+ /** Drain the accumulated buffer and return its content. */
116
+ drainBuffer() {
117
+ return this.native.drainBuffer();
118
+ }
119
+ }
120
+ exports.CognitionStream = CognitionStream;
121
+ /**
122
+ * Tracks the reasoning arc of a conversation and predicts next topics.
123
+ */
124
+ class TrajectoryTracker {
125
+ constructor(maxTurns = 100) {
126
+ this.native = new nativeBinding.JsTrajectoryTracker(maxTurns);
127
+ }
128
+ /**
129
+ * Record a conversation turn.
130
+ *
131
+ * `decisionState` accepts one of:
132
+ * - `"investigating"`
133
+ * - `"interrupted"`
134
+ * - `"completed"`
135
+ * - `"narrowed:<choice>"`
136
+ * - `"decided:<decision>"`
137
+ */
138
+ recordTurn(topic, decisionState, openQuestions = []) {
139
+ this.native.recordTurn(topic, decisionState, openQuestions);
140
+ }
141
+ /** Get a resume context string describing the current trajectory. */
142
+ getResumeContext() {
143
+ return this.native.getResumeContext() ?? null;
144
+ }
145
+ /** Predict the next likely topics based on trajectory. */
146
+ predictNextTopics() {
147
+ return this.native.predictNextTopics();
148
+ }
149
+ }
150
+ exports.TrajectoryTracker = TrajectoryTracker;
package/npm/index.js ADDED
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.EdgeType = exports.MemoryType = exports.TrajectoryTracker = exports.CognitionStream = exports.MenteDB = void 0;
4
+ var client_1 = require("./client");
5
+ Object.defineProperty(exports, "MenteDB", { enumerable: true, get: function () { return client_1.MenteDB; } });
6
+ Object.defineProperty(exports, "CognitionStream", { enumerable: true, get: function () { return client_1.CognitionStream; } });
7
+ Object.defineProperty(exports, "TrajectoryTracker", { enumerable: true, get: function () { return client_1.TrajectoryTracker; } });
8
+ var types_1 = require("./types");
9
+ Object.defineProperty(exports, "MemoryType", { enumerable: true, get: function () { return types_1.MemoryType; } });
10
+ Object.defineProperty(exports, "EdgeType", { enumerable: true, get: function () { return types_1.EdgeType; } });
package/npm/types.d.ts ADDED
@@ -0,0 +1,34 @@
1
+ export declare enum MemoryType {
2
+ Episodic = "episodic",
3
+ Semantic = "semantic",
4
+ Procedural = "procedural",
5
+ AntiPattern = "anti_pattern",
6
+ Reasoning = "reasoning",
7
+ Correction = "correction"
8
+ }
9
+ export declare enum EdgeType {
10
+ Caused = "caused",
11
+ Before = "before",
12
+ Related = "related",
13
+ Contradicts = "contradicts",
14
+ Supports = "supports",
15
+ Supersedes = "supersedes",
16
+ Derived = "derived",
17
+ PartOf = "part_of"
18
+ }
19
+ export interface RecallResult {
20
+ text: string;
21
+ totalTokens: number;
22
+ memoryCount: number;
23
+ }
24
+ export interface SearchResult {
25
+ id: string;
26
+ score: number;
27
+ }
28
+ export interface StoreOptions {
29
+ content: string;
30
+ memoryType?: MemoryType;
31
+ embedding?: number[];
32
+ agentId?: string;
33
+ tags?: string[];
34
+ }
package/npm/types.js ADDED
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.EdgeType = exports.MemoryType = void 0;
4
+ var MemoryType;
5
+ (function (MemoryType) {
6
+ MemoryType["Episodic"] = "episodic";
7
+ MemoryType["Semantic"] = "semantic";
8
+ MemoryType["Procedural"] = "procedural";
9
+ MemoryType["AntiPattern"] = "anti_pattern";
10
+ MemoryType["Reasoning"] = "reasoning";
11
+ MemoryType["Correction"] = "correction";
12
+ })(MemoryType || (exports.MemoryType = MemoryType = {}));
13
+ var EdgeType;
14
+ (function (EdgeType) {
15
+ EdgeType["Caused"] = "caused";
16
+ EdgeType["Before"] = "before";
17
+ EdgeType["Related"] = "related";
18
+ EdgeType["Contradicts"] = "contradicts";
19
+ EdgeType["Supports"] = "supports";
20
+ EdgeType["Supersedes"] = "supersedes";
21
+ EdgeType["Derived"] = "derived";
22
+ EdgeType["PartOf"] = "part_of";
23
+ })(EdgeType || (exports.EdgeType = EdgeType = {}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mentedb",
3
- "version": "0.3.1",
3
+ "version": "0.7.0",
4
4
  "description": "The mind database for AI agents",
5
5
  "main": "npm/index.js",
6
6
  "types": "npm/index.d.ts",
@@ -27,7 +27,11 @@
27
27
  "registry": "https://registry.npmjs.org/"
28
28
  },
29
29
  "napi": {
30
- "name": "mentedb",
30
+ "binaryName": "mentedb",
31
31
  "triples": {}
32
+ },
33
+ "devDependencies": {
34
+ "@types/node": "^25.6.0",
35
+ "typescript": "^6.0.3"
32
36
  }
33
37
  }
package/npm/client.ts DELETED
@@ -1,143 +0,0 @@
1
- import {
2
- MemoryType,
3
- EdgeType,
4
- type StoreOptions,
5
- type RecallResult,
6
- type SearchResult,
7
- } from './types';
8
-
9
- let nativeBinding: any;
10
-
11
- try {
12
- nativeBinding = require('../mentedb.node');
13
- } catch {
14
- nativeBinding = null;
15
- }
16
-
17
- function requireNative(): any {
18
- if (!nativeBinding) {
19
- throw new Error(
20
- 'Native extension not loaded. Build with: npm run build'
21
- );
22
- }
23
- return nativeBinding;
24
- }
25
-
26
- /**
27
- * MenteDB client. Wraps the native Rust database engine and exposes a
28
- * TypeScript-friendly API for storing, recalling, searching, relating, and
29
- * forgetting memories.
30
- */
31
- export class MenteDB {
32
- private native: any;
33
-
34
- constructor(dataDir: string = './mentedb-data') {
35
- const binding = requireNative();
36
- this.native = new binding.MenteDB(dataDir);
37
- }
38
-
39
- /** Store a memory and return its UUID. */
40
- store(options: StoreOptions): string {
41
- const {
42
- content,
43
- memoryType = MemoryType.Episodic,
44
- embedding = [],
45
- agentId,
46
- tags,
47
- } = options;
48
- return this.native.store(content, memoryType, embedding, agentId, tags);
49
- }
50
-
51
- /** Recall memories using an MQL query string. */
52
- recall(query: string): RecallResult {
53
- return this.native.recall(query);
54
- }
55
-
56
- /** Vector similarity search returning top-k results. */
57
- search(embedding: number[], k: number = 10): SearchResult[] {
58
- return this.native.search(embedding, k);
59
- }
60
-
61
- /** Create a typed, weighted edge between two memories. */
62
- relate(
63
- source: string,
64
- target: string,
65
- edgeType: EdgeType = EdgeType.Related,
66
- weight: number = 1.0,
67
- ): void {
68
- this.native.relate(source, target, edgeType, weight);
69
- }
70
-
71
- /** Remove a memory by ID. */
72
- forget(memoryId: string): void {
73
- this.native.forget(memoryId);
74
- }
75
-
76
- /** Flush all data and close the database. */
77
- close(): void {
78
- this.native.close();
79
- }
80
- }
81
-
82
- /**
83
- * Monitors an LLM token stream for contradictions, forgotten facts,
84
- * corrections, and reinforcements.
85
- */
86
- export class CognitionStream {
87
- private native: any;
88
-
89
- constructor(bufferSize: number = 1000) {
90
- const binding = requireNative();
91
- this.native = new binding.JsCognitionStream(bufferSize);
92
- }
93
-
94
- /** Push a token into the stream buffer. */
95
- feedToken(token: string): void {
96
- this.native.feedToken(token);
97
- }
98
-
99
- /** Drain the accumulated buffer and return its content. */
100
- drainBuffer(): string {
101
- return this.native.drainBuffer();
102
- }
103
- }
104
-
105
- /**
106
- * Tracks the reasoning arc of a conversation and predicts next topics.
107
- */
108
- export class TrajectoryTracker {
109
- private native: any;
110
-
111
- constructor(maxTurns: number = 100) {
112
- const binding = requireNative();
113
- this.native = new binding.JsTrajectoryTracker(maxTurns);
114
- }
115
-
116
- /**
117
- * Record a conversation turn.
118
- *
119
- * `decisionState` accepts one of:
120
- * - `"investigating"`
121
- * - `"interrupted"`
122
- * - `"completed"`
123
- * - `"narrowed:<choice>"`
124
- * - `"decided:<decision>"`
125
- */
126
- recordTurn(
127
- topic: string,
128
- decisionState: string,
129
- openQuestions: string[] = [],
130
- ): void {
131
- this.native.recordTurn(topic, decisionState, openQuestions);
132
- }
133
-
134
- /** Get a resume context string describing the current trajectory. */
135
- getResumeContext(): string | null {
136
- return this.native.getResumeContext() ?? null;
137
- }
138
-
139
- /** Predict the next likely topics based on trajectory. */
140
- predictNextTopics(): string[] {
141
- return this.native.predictNextTopics();
142
- }
143
- }
package/npm/types.ts DELETED
@@ -1,38 +0,0 @@
1
- export enum MemoryType {
2
- Episodic = 'episodic',
3
- Semantic = 'semantic',
4
- Procedural = 'procedural',
5
- AntiPattern = 'anti_pattern',
6
- Reasoning = 'reasoning',
7
- Correction = 'correction',
8
- }
9
-
10
- export enum EdgeType {
11
- Caused = 'caused',
12
- Before = 'before',
13
- Related = 'related',
14
- Contradicts = 'contradicts',
15
- Supports = 'supports',
16
- Supersedes = 'supersedes',
17
- Derived = 'derived',
18
- PartOf = 'part_of',
19
- }
20
-
21
- export interface RecallResult {
22
- text: string;
23
- totalTokens: number;
24
- memoryCount: number;
25
- }
26
-
27
- export interface SearchResult {
28
- id: string;
29
- score: number;
30
- }
31
-
32
- export interface StoreOptions {
33
- content: string;
34
- memoryType?: MemoryType;
35
- embedding?: number[];
36
- agentId?: string;
37
- tags?: string[];
38
- }
File without changes