indra_db_mcp 0.1.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/src/types.ts ADDED
@@ -0,0 +1,263 @@
1
+ /**
2
+ * Type definitions for indra_db - A content-addressed graph database for versioned thoughts
3
+ *
4
+ * These types mirror the JSON output from the indra CLI tool.
5
+ */
6
+
7
+ // ============================================================================
8
+ // Core Entities
9
+ // ============================================================================
10
+
11
+ /**
12
+ * A thought is a versioned node in the knowledge graph.
13
+ * Thoughts are content-addressed - their identity comes from their content hash.
14
+ */
15
+ export interface Thought {
16
+ /** Human-readable identifier for the thought */
17
+ id: string;
18
+ /** The actual content/text of the thought */
19
+ content: string;
20
+ /** Vector embedding for semantic search (if available) */
21
+ embedding?: number[];
22
+ /** Arbitrary metadata attached to the thought */
23
+ metadata?: Record<string, unknown>;
24
+ /** ISO 8601 timestamp of creation */
25
+ created_at?: string;
26
+ /** ISO 8601 timestamp of last update */
27
+ updated_at?: string;
28
+ /** Content hash (BLAKE3) */
29
+ hash?: string;
30
+ }
31
+
32
+ /**
33
+ * An edge represents a typed, weighted relationship between two thoughts.
34
+ * Edges "float" - they connect to the latest version of nodes, not pinned hashes.
35
+ */
36
+ export interface Edge {
37
+ /** ID of the source thought */
38
+ source: string;
39
+ /** ID of the target thought */
40
+ target: string;
41
+ /** Type of relationship (e.g., "supports", "contradicts", "derives_from") */
42
+ edge_type: string;
43
+ /** Optional weight for the relationship (0.0 - 1.0) */
44
+ weight?: number;
45
+ /** Arbitrary metadata attached to the edge */
46
+ metadata?: Record<string, unknown>;
47
+ }
48
+
49
+ /**
50
+ * Built-in edge types with semantic meaning.
51
+ * Custom types are also supported - use any string.
52
+ */
53
+ export const EdgeTypes = {
54
+ /** General relationship - when the connection exists but type is unclear */
55
+ RELATES_TO: "relates_to",
56
+ /** Evidence or support - this thought backs up another */
57
+ SUPPORTS: "supports",
58
+ /** Contradiction - this thought conflicts with another */
59
+ CONTRADICTS: "contradicts",
60
+ /** Derivation - this thought is derived/evolved from another */
61
+ DERIVES_FROM: "derives_from",
62
+ /** Hierarchy - this thought is part of a larger concept */
63
+ PART_OF: "part_of",
64
+ /** Similarity - these thoughts express related ideas */
65
+ SIMILAR_TO: "similar_to",
66
+ /** Causation - this thought causes/leads to another */
67
+ CAUSES: "causes",
68
+ /** Temporal ordering - this thought precedes another in time */
69
+ PRECEDES: "precedes",
70
+ } as const;
71
+
72
+ export type EdgeType = (typeof EdgeTypes)[keyof typeof EdgeTypes] | string;
73
+
74
+ // ============================================================================
75
+ // Search & Traversal
76
+ // ============================================================================
77
+
78
+ /**
79
+ * A search result with similarity score.
80
+ * Higher scores indicate greater semantic similarity to the query.
81
+ */
82
+ export interface SearchResult {
83
+ /** The matching thought */
84
+ thought: Thought;
85
+ /** Similarity score (typically 0.0 - 1.0, higher is more similar) */
86
+ score: number;
87
+ }
88
+
89
+ /**
90
+ * A neighbor in the graph with the connecting edge.
91
+ */
92
+ export interface Neighbor {
93
+ /** The neighboring thought */
94
+ thought: Thought;
95
+ /** The edge connecting to this neighbor */
96
+ edge: Edge;
97
+ }
98
+
99
+ /**
100
+ * Direction for graph traversal.
101
+ */
102
+ export type TraversalDirection = "outgoing" | "incoming" | "both";
103
+
104
+ // ============================================================================
105
+ // Versioning (Git-like)
106
+ // ============================================================================
107
+
108
+ /**
109
+ * A commit represents a snapshot of the database at a point in time.
110
+ * Like git, commits are content-addressed and form a DAG.
111
+ */
112
+ export interface Commit {
113
+ /** Content hash of this commit */
114
+ hash: string;
115
+ /** Human-readable commit message */
116
+ message: string;
117
+ /** ISO 8601 timestamp */
118
+ timestamp: string;
119
+ /** Hash of parent commit (if any) */
120
+ parent?: string;
121
+ /** Hash of the tree (merkle trie root) */
122
+ tree_hash?: string;
123
+ }
124
+
125
+ /**
126
+ * A branch is a named pointer to a commit.
127
+ */
128
+ export interface Branch {
129
+ /** Branch name */
130
+ name: string;
131
+ /** Hash of the commit this branch points to */
132
+ commit_hash: string;
133
+ /** Whether this is the current HEAD branch */
134
+ is_current?: boolean;
135
+ }
136
+
137
+ /**
138
+ * Diff information between two commits.
139
+ */
140
+ export interface Diff {
141
+ /** Thoughts added */
142
+ added: Thought[];
143
+ /** Thoughts removed */
144
+ removed: Thought[];
145
+ /** Thoughts modified (before/after pairs) */
146
+ modified: Array<{ before: Thought; after: Thought }>;
147
+ /** Edges added */
148
+ edges_added: Edge[];
149
+ /** Edges removed */
150
+ edges_removed: Edge[];
151
+ }
152
+
153
+ // ============================================================================
154
+ // Database Status
155
+ // ============================================================================
156
+
157
+ /**
158
+ * Current status of the database.
159
+ */
160
+ export interface DatabaseStatus {
161
+ /** Current branch name */
162
+ branch: string;
163
+ /** Database file path */
164
+ database: string;
165
+ /** Whether there are uncommitted changes */
166
+ dirty: boolean;
167
+ }
168
+
169
+ // ============================================================================
170
+ // CLI Response Wrappers
171
+ // ============================================================================
172
+
173
+ export interface ListThoughtsResponse {
174
+ count: number;
175
+ thoughts: Array<{
176
+ id: string;
177
+ content: string;
178
+ has_embedding: boolean;
179
+ type?: string | null;
180
+ }>;
181
+ }
182
+
183
+ export interface SearchResponse {
184
+ query: string;
185
+ count: number;
186
+ results: Array<{
187
+ id: string;
188
+ content: string;
189
+ score: number;
190
+ }>;
191
+ }
192
+
193
+ export interface NeighborsResponse {
194
+ thought_id: string;
195
+ direction: TraversalDirection;
196
+ count: number;
197
+ neighbors: Neighbor[];
198
+ }
199
+
200
+ export interface LogResponse {
201
+ branch: string;
202
+ commits: Commit[];
203
+ }
204
+
205
+ export interface BranchesResponse {
206
+ current: string;
207
+ branches: Branch[];
208
+ }
209
+
210
+ export interface CommitResponse {
211
+ hash: string;
212
+ message: string;
213
+ timestamp: string;
214
+ changes: {
215
+ thoughts_added: number;
216
+ thoughts_modified: number;
217
+ thoughts_removed: number;
218
+ edges_added: number;
219
+ edges_removed: number;
220
+ };
221
+ }
222
+
223
+ // ============================================================================
224
+ // Error Types
225
+ // ============================================================================
226
+
227
+ export interface IndraErrorInfo {
228
+ code: string;
229
+ message: string;
230
+ details?: string;
231
+ }
232
+
233
+ export class IndraError extends Error {
234
+ public readonly exitCode: number;
235
+ public readonly stderr: string;
236
+ public readonly command: string[];
237
+ public readonly errorCode?: string;
238
+
239
+ constructor(
240
+ message: string,
241
+ exitCode: number,
242
+ stderr: string,
243
+ command: string[]
244
+ ) {
245
+ super(message);
246
+ this.name = "IndraError";
247
+ this.exitCode = exitCode;
248
+ this.stderr = stderr;
249
+ this.command = command;
250
+
251
+ // Try to extract error code from stderr
252
+ const codeMatch = stderr.match(/error\[(\w+)\]/i);
253
+ this.errorCode = codeMatch?.[1];
254
+ }
255
+
256
+ toJSON(): IndraErrorInfo {
257
+ return {
258
+ code: this.errorCode || "UNKNOWN",
259
+ message: this.message,
260
+ details: this.stderr,
261
+ };
262
+ }
263
+ }