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/dist/index.mjs ADDED
@@ -0,0 +1,227 @@
1
+ // src/client.ts
2
+ var MindGraphError = class extends Error {
3
+ constructor(message, status, body) {
4
+ super(message);
5
+ this.status = status;
6
+ this.body = body;
7
+ this.name = "MindGraphError";
8
+ }
9
+ };
10
+ var MindGraph = class {
11
+ constructor(config) {
12
+ this.baseUrl = config.baseUrl.replace(/\/$/, "");
13
+ this.headers = { "Content-Type": "application/json" };
14
+ if (config.apiKey) {
15
+ this.headers["Authorization"] = `Bearer ${config.apiKey}`;
16
+ } else if (config.jwt) {
17
+ this.headers["Authorization"] = `Bearer ${config.jwt}`;
18
+ }
19
+ }
20
+ // ---- HTTP helpers ----
21
+ async request(method, path, body) {
22
+ const url = `${this.baseUrl}${path}`;
23
+ const init = {
24
+ method,
25
+ headers: this.headers
26
+ };
27
+ if (body !== void 0) {
28
+ init.body = JSON.stringify(body);
29
+ }
30
+ const res = await fetch(url, init);
31
+ if (!res.ok) {
32
+ const text2 = await res.text().catch(() => "");
33
+ let parsed;
34
+ try {
35
+ parsed = JSON.parse(text2);
36
+ } catch {
37
+ parsed = text2;
38
+ }
39
+ throw new MindGraphError(
40
+ `${method} ${path} failed: ${res.status}`,
41
+ res.status,
42
+ parsed
43
+ );
44
+ }
45
+ const text = await res.text();
46
+ if (!text) return void 0;
47
+ return JSON.parse(text);
48
+ }
49
+ get(path) {
50
+ return this.request("GET", path);
51
+ }
52
+ post(path, body) {
53
+ return this.request("POST", path, body);
54
+ }
55
+ patch(path, body) {
56
+ return this.request("PATCH", path, body);
57
+ }
58
+ del(path) {
59
+ return this.request("DELETE", path);
60
+ }
61
+ // ---- Health ----
62
+ async health() {
63
+ return this.get("/health");
64
+ }
65
+ async stats() {
66
+ return this.get("/stats");
67
+ }
68
+ // ---- Reality Layer ----
69
+ async ingest(req) {
70
+ return this.post("/reality/ingest", req);
71
+ }
72
+ async entity(req) {
73
+ return this.post("/reality/entity", req);
74
+ }
75
+ /** Convenience: create or find an entity by label. */
76
+ async findOrCreateEntity(label, entityType = "other", agentId) {
77
+ return this.post("/reality/entity", {
78
+ action: "create",
79
+ label,
80
+ entity_type: entityType,
81
+ agent_id: agentId
82
+ });
83
+ }
84
+ // ---- Epistemic Layer ----
85
+ async argue(req) {
86
+ return this.post("/epistemic/argument", req);
87
+ }
88
+ async inquire(req) {
89
+ return this.post("/epistemic/inquiry", req);
90
+ }
91
+ async structure(req) {
92
+ return this.post("/epistemic/structure", req);
93
+ }
94
+ // ---- Intent Layer ----
95
+ async commit(req) {
96
+ return this.post("/intent/commitment", req);
97
+ }
98
+ async deliberate(req) {
99
+ return this.post("/intent/deliberation", req);
100
+ }
101
+ // ---- Action Layer ----
102
+ async procedure(req) {
103
+ return this.post("/action/procedure", req);
104
+ }
105
+ async risk(req) {
106
+ return this.post("/action/risk", req);
107
+ }
108
+ // ---- Memory Layer ----
109
+ async session(req) {
110
+ return this.post("/memory/session", req);
111
+ }
112
+ async distill(req) {
113
+ return this.post("/memory/distill", req);
114
+ }
115
+ async memoryConfig(req) {
116
+ return this.post("/memory/config", req);
117
+ }
118
+ // ---- Agent Layer ----
119
+ async plan(req) {
120
+ return this.post("/agent/plan", req);
121
+ }
122
+ async governance(req) {
123
+ return this.post("/agent/governance", req);
124
+ }
125
+ async execution(req) {
126
+ return this.post("/agent/execution", req);
127
+ }
128
+ // ---- Cross-cutting ----
129
+ async retrieve(req) {
130
+ return this.post("/retrieve", req);
131
+ }
132
+ async traverse(req) {
133
+ return this.post("/traverse", req);
134
+ }
135
+ async evolve(req) {
136
+ return this.post("/evolve", req);
137
+ }
138
+ // ---- Node CRUD ----
139
+ async getNode(uid) {
140
+ return this.get(`/node/${uid}`);
141
+ }
142
+ async addNode(body) {
143
+ return this.post("/node", body);
144
+ }
145
+ async updateNode(uid, body) {
146
+ return this.patch(`/node/${uid}`, body);
147
+ }
148
+ async deleteNode(uid) {
149
+ await this.del(`/node/${uid}`);
150
+ }
151
+ // ---- Edge CRUD ----
152
+ async addLink(body) {
153
+ return this.post("/link", body);
154
+ }
155
+ async getEdges(params) {
156
+ const qs = new URLSearchParams();
157
+ if (params.from_uid) qs.set("from_uid", params.from_uid);
158
+ if (params.to_uid) qs.set("to_uid", params.to_uid);
159
+ return this.get(`/edges?${qs}`);
160
+ }
161
+ // ---- Search ----
162
+ async search(query, opts) {
163
+ return this.post("/search", { query, ...opts });
164
+ }
165
+ /** Hybrid BM25 + vector search with reciprocal rank fusion. */
166
+ async hybridSearch(query, opts) {
167
+ return this.post("/retrieve", {
168
+ action: "hybrid",
169
+ query,
170
+ ...opts
171
+ });
172
+ }
173
+ // ---- Traversal shortcuts ----
174
+ async reasoningChain(uid, maxDepth = 5) {
175
+ return this.post("/traverse", {
176
+ action: "chain",
177
+ start_uid: uid,
178
+ max_depth: maxDepth
179
+ });
180
+ }
181
+ async neighborhood(uid, maxDepth = 1) {
182
+ return this.post("/traverse", {
183
+ action: "neighborhood",
184
+ start_uid: uid,
185
+ max_depth: maxDepth
186
+ });
187
+ }
188
+ // ---- Lifecycle shortcuts ----
189
+ async tombstone(uid, reason, agentId) {
190
+ return this.post("/evolve", {
191
+ action: "tombstone",
192
+ uid,
193
+ reason,
194
+ agent_id: agentId
195
+ });
196
+ }
197
+ async restore(uid, agentId) {
198
+ return this.post("/evolve", {
199
+ action: "restore",
200
+ uid,
201
+ agent_id: agentId
202
+ });
203
+ }
204
+ // ---- Management (Cloud only) ----
205
+ async signup(email, password) {
206
+ return this.post("/v1/auth/signup", { email, password });
207
+ }
208
+ async login(email, password) {
209
+ return this.post("/v1/auth/login", { email, password });
210
+ }
211
+ async createApiKey(name = "default") {
212
+ return this.post("/v1/api-keys", { name });
213
+ }
214
+ async listApiKeys() {
215
+ return this.get("/v1/api-keys");
216
+ }
217
+ async revokeApiKey(id) {
218
+ await this.del(`/v1/api-keys/${id}`);
219
+ }
220
+ async getUsage() {
221
+ return this.get("/v1/usage");
222
+ }
223
+ };
224
+ export {
225
+ MindGraph,
226
+ MindGraphError
227
+ };
package/package.json ADDED
@@ -0,0 +1,21 @@
1
+ {
2
+ "name": "mindgraph",
3
+ "version": "0.1.0",
4
+ "description": "TypeScript client for the MindGraph Cloud API",
5
+ "main": "dist/index.js",
6
+ "module": "dist/index.mjs",
7
+ "types": "dist/index.d.ts",
8
+ "files": ["dist"],
9
+ "scripts": {
10
+ "build": "tsup src/index.ts --format cjs,esm --dts",
11
+ "lint": "tsc --noEmit",
12
+ "test": "vitest run"
13
+ },
14
+ "keywords": ["mindgraph", "knowledge-graph", "cognitive", "ai", "agent"],
15
+ "license": "MIT",
16
+ "devDependencies": {
17
+ "tsup": "^8.0.0",
18
+ "typescript": "^5.7.0",
19
+ "vitest": "^3.0.0"
20
+ }
21
+ }