mindgraph 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/README.md ADDED
@@ -0,0 +1,153 @@
1
+ # mindgraph
2
+
3
+ [![npm](https://img.shields.io/npm/v/mindgraph)](https://www.npmjs.com/package/mindgraph)
4
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
5
+
6
+ TypeScript client for the [MindGraph Cloud](https://mindgraph.cloud) API — a structured semantic memory graph for AI agents.
7
+
8
+ ## Install
9
+
10
+ ```bash
11
+ npm install mindgraph
12
+ ```
13
+
14
+ ## Quick Start
15
+
16
+ ```typescript
17
+ import { MindGraph } from "mindgraph";
18
+
19
+ const graph = new MindGraph({
20
+ baseUrl: "https://api.mindgraph.cloud",
21
+ apiKey: "mg_...",
22
+ });
23
+
24
+ // Add a node
25
+ const node = await graph.addNode({
26
+ label: "User prefers dark mode",
27
+ node_type: "Preference",
28
+ });
29
+
30
+ // Search
31
+ const results = await graph.search("what does the user prefer?");
32
+
33
+ // Connect knowledge
34
+ await graph.addLink({
35
+ from_uid: node.uid,
36
+ to_uid: "user_abc",
37
+ edge_type: "BelongsTo",
38
+ });
39
+ ```
40
+
41
+ ## API Reference
42
+
43
+ ### Constructor
44
+
45
+ ```typescript
46
+ new MindGraph({ baseUrl: string, apiKey?: string, jwt?: string })
47
+ ```
48
+
49
+ ### Reality Layer
50
+
51
+ | Method | Description |
52
+ |--------|-------------|
53
+ | `ingest(req)` | Ingest a source, snippet, or observation |
54
+ | `entity(req)` | Create, alias, resolve, or merge entities |
55
+ | `findOrCreateEntity(label, entityType?, agentId?)` | Convenience: create or find an entity by label |
56
+
57
+ ### Epistemic Layer
58
+
59
+ | Method | Description |
60
+ |--------|-------------|
61
+ | `argue(req)` | Construct a full argument: claim + evidence + warrant + edges |
62
+ | `inquire(req)` | Add hypothesis, theory, paradigm, anomaly, assumption, or question |
63
+ | `structure(req)` | Add concept, pattern, mechanism, model, analogy, theorem, etc. |
64
+
65
+ ### Intent Layer
66
+
67
+ | Method | Description |
68
+ |--------|-------------|
69
+ | `commit(req)` | Create a goal, project, or milestone |
70
+ | `deliberate(req)` | Open decisions, add options/constraints, resolve decisions |
71
+
72
+ ### Action Layer
73
+
74
+ | Method | Description |
75
+ |--------|-------------|
76
+ | `procedure(req)` | Build flows, add steps, affordances, and controls |
77
+ | `risk(req)` | Assess risk or retrieve existing assessments |
78
+
79
+ ### Memory Layer
80
+
81
+ | Method | Description |
82
+ |--------|-------------|
83
+ | `session(req)` | Open a session, record traces, or close a session |
84
+ | `distill(req)` | Create a summary that distills multiple source nodes |
85
+ | `memoryConfig(req)` | Set/get preferences and memory policies |
86
+
87
+ ### Agent Layer
88
+
89
+ | Method | Description |
90
+ |--------|-------------|
91
+ | `plan(req)` | Create tasks, plans, plan steps, update status |
92
+ | `governance(req)` | Create policies, set safety budgets, request/resolve approvals |
93
+ | `execution(req)` | Track execution lifecycle and register agents |
94
+
95
+ ### CRUD
96
+
97
+ | Method | Description |
98
+ |--------|-------------|
99
+ | `getNode(uid)` | Get a node by UID |
100
+ | `addNode({ label, node_type?, props?, agent_id? })` | Add a generic node |
101
+ | `updateNode(uid, { label?, summary?, confidence?, salience? })` | Update node fields |
102
+ | `deleteNode(uid)` | Tombstone a node and all connected edges |
103
+ | `addLink({ from_uid, to_uid, edge_type, agent_id? })` | Add a typed edge |
104
+ | `getEdges({ from_uid?, to_uid? })` | Get edges by source or target |
105
+
106
+ ### Search
107
+
108
+ | Method | Description |
109
+ |--------|-------------|
110
+ | `search(query, { node_type?, layer?, limit? })` | Full-text search |
111
+ | `hybridSearch(query, { k?, node_types?, layer? })` | BM25 + vector search with rank fusion |
112
+
113
+ ### Traversal
114
+
115
+ | Method | Description |
116
+ |--------|-------------|
117
+ | `reasoningChain(uid, maxDepth?)` | Follow epistemic edges from a node |
118
+ | `neighborhood(uid, maxDepth?)` | Get all nodes within N hops |
119
+
120
+ ### Cross-cutting
121
+
122
+ | Method | Description |
123
+ |--------|-------------|
124
+ | `retrieve(req)` | Unified retrieval: text search, active goals, open questions, weak claims |
125
+ | `traverse(req)` | Graph traversal: chain, neighborhood, path, or subgraph |
126
+ | `evolve(req)` | Lifecycle mutations: update, tombstone, restore, decay, history |
127
+
128
+ ### Health & Stats
129
+
130
+ | Method | Description |
131
+ |--------|-------------|
132
+ | `health()` | Health check |
133
+ | `stats()` | Graph-wide statistics |
134
+
135
+ ## Error Handling
136
+
137
+ All methods throw `MindGraphError` on HTTP errors:
138
+
139
+ ```typescript
140
+ import { MindGraphError } from "mindgraph";
141
+
142
+ try {
143
+ await graph.getNode("nonexistent");
144
+ } catch (err) {
145
+ if (err instanceof MindGraphError) {
146
+ console.error(err.status, err.body);
147
+ }
148
+ }
149
+ ```
150
+
151
+ ## License
152
+
153
+ MIT
@@ -0,0 +1,393 @@
1
+ interface GraphNode {
2
+ uid: string;
3
+ label: string;
4
+ summary: string;
5
+ node_type: string;
6
+ layer: string;
7
+ confidence: number;
8
+ salience: number;
9
+ props: Record<string, unknown>;
10
+ created_at: number;
11
+ updated_at: number;
12
+ tombstone_at: number | null;
13
+ }
14
+ interface GraphEdge {
15
+ uid: string;
16
+ from_uid: string;
17
+ to_uid: string;
18
+ edge_type: string;
19
+ layer: string;
20
+ weight: number;
21
+ props: Record<string, unknown>;
22
+ created_at: number;
23
+ updated_at: number;
24
+ tombstone_at: number | null;
25
+ }
26
+ interface SearchResult {
27
+ uid: string;
28
+ label: string;
29
+ summary: string;
30
+ node_type: string;
31
+ score: number;
32
+ }
33
+ interface PathStep {
34
+ uid: string;
35
+ label: string;
36
+ node_type: string;
37
+ edge_type: string | null;
38
+ depth: number;
39
+ parent_uid: string | null;
40
+ }
41
+ interface IngestRequest {
42
+ action: "source" | "snippet" | "observation";
43
+ label: string;
44
+ content: string;
45
+ source_uid?: string;
46
+ medium?: string;
47
+ url?: string;
48
+ timestamp?: number;
49
+ confidence?: number;
50
+ salience?: number;
51
+ agent_id?: string;
52
+ }
53
+ interface EntityRequest {
54
+ action: "create" | "alias" | "resolve" | "fuzzy_resolve" | "merge" | "relate";
55
+ label?: string;
56
+ entity_type?: string;
57
+ text?: string;
58
+ canonical_uid?: string;
59
+ alias_score?: number;
60
+ keep_uid?: string;
61
+ merge_uid?: string;
62
+ limit?: number;
63
+ source_uid?: string;
64
+ target_uid?: string;
65
+ edge_type?: string;
66
+ agent_id?: string;
67
+ }
68
+ interface ArgumentRequest {
69
+ claim: {
70
+ label: string;
71
+ content: string;
72
+ confidence?: number;
73
+ };
74
+ evidence?: {
75
+ label: string;
76
+ description: string;
77
+ evidence_type?: string;
78
+ }[];
79
+ warrant?: {
80
+ label: string;
81
+ principle: string;
82
+ };
83
+ argument?: {
84
+ label: string;
85
+ summary: string;
86
+ };
87
+ refutes_uid?: string;
88
+ extends_uid?: string;
89
+ source_uids?: string[];
90
+ agent_id?: string;
91
+ }
92
+ interface InquiryRequest {
93
+ action: "hypothesis" | "theory" | "paradigm" | "anomaly" | "assumption" | "question" | "open_question";
94
+ label: string;
95
+ content: string;
96
+ status?: string;
97
+ anomalous_to_uid?: string;
98
+ assumes_uid?: string[];
99
+ tests_uid?: string;
100
+ addresses_uid?: string;
101
+ confidence?: number;
102
+ salience?: number;
103
+ related_uids?: string[];
104
+ agent_id?: string;
105
+ }
106
+ interface StructureRequest {
107
+ action: "concept" | "pattern" | "mechanism" | "model" | "model_evaluation" | "analogy" | "inference_chain" | "reasoning_strategy" | "sensitivity_analysis" | "theorem" | "equation";
108
+ label: string;
109
+ content: string;
110
+ summary?: string;
111
+ analogous_to_uid?: string;
112
+ transfers_to_uid?: string[];
113
+ evaluates_uid?: string;
114
+ outperforms_uid?: string;
115
+ chain_steps?: string[];
116
+ derived_from_uid?: string[];
117
+ proven_by_uid?: string;
118
+ related_uids?: string[];
119
+ confidence?: number;
120
+ agent_id?: string;
121
+ }
122
+ interface CommitmentRequest {
123
+ action: "goal" | "project" | "milestone";
124
+ label: string;
125
+ description: string;
126
+ priority?: string;
127
+ status?: string;
128
+ parent_uid?: string;
129
+ due_date?: number;
130
+ motivated_by_uid?: string[];
131
+ agent_id?: string;
132
+ }
133
+ interface DeliberationRequest {
134
+ action: "open_decision" | "add_option" | "add_constraint" | "resolve" | "get_open";
135
+ label?: string;
136
+ description?: string;
137
+ decision_uid?: string;
138
+ chosen_option_uid?: string;
139
+ resolution_rationale?: string;
140
+ constraint_type?: string;
141
+ blocks_uid?: string;
142
+ informs_uid?: string[];
143
+ agent_id?: string;
144
+ }
145
+ interface ProcedureRequest {
146
+ action: "create_flow" | "add_step" | "add_affordance" | "add_control";
147
+ label: string;
148
+ description?: string;
149
+ flow_uid?: string;
150
+ step_order?: number;
151
+ previous_step_uid?: string;
152
+ affordance_type?: string;
153
+ control_type?: string;
154
+ uses_affordance_uids?: string[];
155
+ goal_uid?: string;
156
+ agent_id?: string;
157
+ }
158
+ interface RiskRequest {
159
+ action: "assess" | "get_assessments";
160
+ label?: string;
161
+ description?: string;
162
+ assessed_uid?: string;
163
+ severity?: string;
164
+ likelihood?: number;
165
+ mitigations?: string[];
166
+ residual_risk?: number;
167
+ filter_uid?: string;
168
+ agent_id?: string;
169
+ }
170
+ interface SessionRequest {
171
+ action: "open" | "trace" | "close";
172
+ label?: string;
173
+ focus?: string;
174
+ session_uid?: string;
175
+ trace_content?: string;
176
+ trace_type?: string;
177
+ relevant_node_uids?: string[];
178
+ agent_id?: string;
179
+ }
180
+ interface DistillRequest {
181
+ label: string;
182
+ content: string;
183
+ summarizes_uids?: string[];
184
+ session_uid?: string;
185
+ importance?: number;
186
+ agent_id?: string;
187
+ }
188
+ interface MemoryConfigRequest {
189
+ action: "set_preference" | "get_preferences" | "set_policy" | "get_policies";
190
+ label?: string;
191
+ key?: string;
192
+ value?: string;
193
+ policy_content?: string;
194
+ agent_id?: string;
195
+ }
196
+ interface PlanRequest {
197
+ action: "create_task" | "create_plan" | "add_step" | "update_status" | "get_plan";
198
+ label?: string;
199
+ description?: string;
200
+ goal_uid?: string;
201
+ task_uid?: string;
202
+ plan_uid?: string;
203
+ step_order?: number;
204
+ depends_on_uids?: string[];
205
+ target_uid?: string;
206
+ status?: string;
207
+ related_uids?: string[];
208
+ agent_id?: string;
209
+ }
210
+ interface GovernanceRequest {
211
+ action: "create_policy" | "set_budget" | "request_approval" | "resolve_approval" | "get_pending";
212
+ label?: string;
213
+ policy_content?: string;
214
+ budget_type?: string;
215
+ budget_limit?: number;
216
+ governed_uid?: string;
217
+ approval_uid?: string;
218
+ approved?: boolean;
219
+ resolution_note?: string;
220
+ requires_plan_uid?: string;
221
+ approval_request?: string;
222
+ agent_id?: string;
223
+ }
224
+ interface ExecutionRequest {
225
+ action: "start" | "complete" | "fail" | "register_agent" | "get_executions";
226
+ label?: string;
227
+ plan_uid?: string;
228
+ executor_uid?: string;
229
+ execution_uid?: string;
230
+ outcome?: string;
231
+ produces_node_uid?: string;
232
+ error_description?: string;
233
+ agent_name?: string;
234
+ agent_role?: string;
235
+ filter_plan_uid?: string;
236
+ related_uids?: string[];
237
+ agent_id?: string;
238
+ }
239
+ interface RetrieveRequest {
240
+ action: "text" | "semantic" | "hybrid" | "active_goals" | "open_questions" | "weak_claims" | "pending_approvals" | "unresolved_contradictions" | "layer" | "recent";
241
+ query?: string;
242
+ k?: number;
243
+ threshold?: number;
244
+ layer?: string;
245
+ node_types?: string[];
246
+ confidence_min?: number;
247
+ salience_min?: number;
248
+ limit?: number;
249
+ offset?: number;
250
+ }
251
+ interface TraverseRequest {
252
+ action: "chain" | "neighborhood" | "path" | "subgraph";
253
+ start_uid: string;
254
+ end_uid?: string;
255
+ max_depth?: number;
256
+ direction?: "outgoing" | "incoming" | "both";
257
+ edge_types?: string[];
258
+ weight_threshold?: number;
259
+ }
260
+ interface EvolveRequest {
261
+ action: "update" | "tombstone" | "restore" | "decay" | "history" | "snapshot" | "tombstone_edge" | "restore_edge" | "tombstone_cascade";
262
+ uid: string;
263
+ label?: string;
264
+ summary?: string;
265
+ confidence?: number;
266
+ salience?: number;
267
+ props_patch?: Record<string, unknown>;
268
+ reason?: string;
269
+ cascade?: boolean;
270
+ half_life_secs?: number;
271
+ min_salience?: number;
272
+ min_age_secs?: number;
273
+ version?: number;
274
+ agent_id?: string;
275
+ }
276
+ interface SignupRequest {
277
+ email: string;
278
+ password: string;
279
+ }
280
+ interface LoginRequest {
281
+ email: string;
282
+ password: string;
283
+ }
284
+ interface CreateOrgRequest {
285
+ name: string;
286
+ slug?: string;
287
+ }
288
+ interface CreateApiKeyRequest {
289
+ name?: string;
290
+ }
291
+ interface ApiKeyResponse {
292
+ id: string;
293
+ key: string;
294
+ name: string;
295
+ prefix: string;
296
+ }
297
+ interface MindGraphConfig {
298
+ baseUrl: string;
299
+ apiKey?: string;
300
+ jwt?: string;
301
+ }
302
+
303
+ declare class MindGraphError extends Error {
304
+ status: number;
305
+ body?: unknown | undefined;
306
+ constructor(message: string, status: number, body?: unknown | undefined);
307
+ }
308
+ declare class MindGraph {
309
+ private baseUrl;
310
+ private headers;
311
+ constructor(config: MindGraphConfig);
312
+ private request;
313
+ private get;
314
+ private post;
315
+ private patch;
316
+ private del;
317
+ health(): Promise<{
318
+ status: string;
319
+ }>;
320
+ stats(): Promise<Record<string, unknown>>;
321
+ ingest(req: IngestRequest): Promise<unknown>;
322
+ entity(req: EntityRequest): Promise<unknown>;
323
+ /** Convenience: create or find an entity by label. */
324
+ findOrCreateEntity(label: string, entityType?: string, agentId?: string): Promise<GraphNode & {
325
+ created: boolean;
326
+ }>;
327
+ argue(req: ArgumentRequest): Promise<unknown>;
328
+ inquire(req: InquiryRequest): Promise<unknown>;
329
+ structure(req: StructureRequest): Promise<unknown>;
330
+ commit(req: CommitmentRequest): Promise<unknown>;
331
+ deliberate(req: DeliberationRequest): Promise<unknown>;
332
+ procedure(req: ProcedureRequest): Promise<unknown>;
333
+ risk(req: RiskRequest): Promise<unknown>;
334
+ session(req: SessionRequest): Promise<unknown>;
335
+ distill(req: DistillRequest): Promise<unknown>;
336
+ memoryConfig(req: MemoryConfigRequest): Promise<unknown>;
337
+ plan(req: PlanRequest): Promise<unknown>;
338
+ governance(req: GovernanceRequest): Promise<unknown>;
339
+ execution(req: ExecutionRequest): Promise<unknown>;
340
+ retrieve(req: RetrieveRequest): Promise<unknown>;
341
+ traverse(req: TraverseRequest): Promise<unknown>;
342
+ evolve(req: EvolveRequest): Promise<unknown>;
343
+ getNode(uid: string): Promise<GraphNode>;
344
+ addNode(body: {
345
+ label: string;
346
+ node_type?: string;
347
+ props?: Record<string, unknown>;
348
+ agent_id?: string;
349
+ }): Promise<GraphNode>;
350
+ updateNode(uid: string, body: {
351
+ label?: string;
352
+ summary?: string;
353
+ confidence?: number;
354
+ salience?: number;
355
+ agent_id?: string;
356
+ }): Promise<GraphNode>;
357
+ deleteNode(uid: string): Promise<void>;
358
+ addLink(body: {
359
+ from_uid: string;
360
+ to_uid: string;
361
+ edge_type: string;
362
+ agent_id?: string;
363
+ }): Promise<unknown>;
364
+ getEdges(params: {
365
+ from_uid?: string;
366
+ to_uid?: string;
367
+ }): Promise<GraphEdge[]>;
368
+ search(query: string, opts?: {
369
+ node_type?: string;
370
+ layer?: string;
371
+ limit?: number;
372
+ }): Promise<SearchResult[]>;
373
+ /** Hybrid BM25 + vector search with reciprocal rank fusion. */
374
+ hybridSearch(query: string, opts?: {
375
+ k?: number;
376
+ node_types?: string[];
377
+ layer?: string;
378
+ }): Promise<SearchResult[]>;
379
+ reasoningChain(uid: string, maxDepth?: number): Promise<PathStep[]>;
380
+ neighborhood(uid: string, maxDepth?: number): Promise<PathStep[]>;
381
+ tombstone(uid: string, reason?: string, agentId?: string): Promise<unknown>;
382
+ restore(uid: string, agentId?: string): Promise<unknown>;
383
+ signup(email: string, password: string): Promise<unknown>;
384
+ login(email: string, password: string): Promise<unknown>;
385
+ createApiKey(name?: string): Promise<ApiKeyResponse>;
386
+ listApiKeys(): Promise<{
387
+ api_keys: unknown[];
388
+ }>;
389
+ revokeApiKey(id: string): Promise<void>;
390
+ getUsage(): Promise<unknown>;
391
+ }
392
+
393
+ export { type ApiKeyResponse, type ArgumentRequest, type CommitmentRequest, type CreateApiKeyRequest, type CreateOrgRequest, type DeliberationRequest, type DistillRequest, type EntityRequest, type EvolveRequest, type ExecutionRequest, type GovernanceRequest, type GraphEdge, type GraphNode, type IngestRequest, type InquiryRequest, type LoginRequest, type MemoryConfigRequest, MindGraph, type MindGraphConfig, MindGraphError, type PathStep, type PlanRequest, type ProcedureRequest, type RetrieveRequest, type RiskRequest, type SearchResult, type SessionRequest, type SignupRequest, type StructureRequest, type TraverseRequest };