mindgraph 0.12.0 → 0.14.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/LICENSE +1 -1
- package/dist/index.d.mts +247 -16
- package/dist/index.d.ts +247 -16
- package/dist/index.js +107 -55
- package/dist/index.mjs +107 -55
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
// src/client.ts
|
|
2
|
+
function seg(value) {
|
|
3
|
+
return encodeURIComponent(String(value));
|
|
4
|
+
}
|
|
2
5
|
var MindGraphError = class extends Error {
|
|
3
6
|
constructor(message, status, body) {
|
|
4
7
|
super(message);
|
|
@@ -19,15 +22,21 @@ var MindGraph = class {
|
|
|
19
22
|
if (config.orgId) {
|
|
20
23
|
this.headers["X-MindGraph-Org"] = config.orgId;
|
|
21
24
|
}
|
|
25
|
+
this.telemetrySurface = config.telemetrySurface;
|
|
22
26
|
this.maxRetries = config.maxRetries ?? 3;
|
|
23
27
|
this.retryBackoffMs = config.retryBackoffMs ?? 1e3;
|
|
24
28
|
}
|
|
25
29
|
// ---- HTTP helpers ----
|
|
26
30
|
async request(method, path, body) {
|
|
27
31
|
const url = `${this.baseUrl}${path}`;
|
|
32
|
+
const requestId = createRequestId();
|
|
28
33
|
const init = {
|
|
29
34
|
method,
|
|
30
|
-
headers:
|
|
35
|
+
headers: {
|
|
36
|
+
...this.headers,
|
|
37
|
+
"X-MindGraph-Request-ID": requestId,
|
|
38
|
+
...this.telemetrySurface ? { "X-MindGraph-Surface": this.telemetrySurface } : {}
|
|
39
|
+
}
|
|
31
40
|
};
|
|
32
41
|
if (body !== void 0) {
|
|
33
42
|
init.body = JSON.stringify(body);
|
|
@@ -262,6 +271,9 @@ var MindGraph = class {
|
|
|
262
271
|
async memoryConfig(req) {
|
|
263
272
|
return this.post("/memory/config", req);
|
|
264
273
|
}
|
|
274
|
+
async memorySync(req) {
|
|
275
|
+
return this.post("/memory/sync", req);
|
|
276
|
+
}
|
|
265
277
|
// ---- Agent Layer ----
|
|
266
278
|
async plan(req) {
|
|
267
279
|
return this.post("/agent/plan", req);
|
|
@@ -285,7 +297,7 @@ var MindGraph = class {
|
|
|
285
297
|
}
|
|
286
298
|
// ---- Node CRUD ----
|
|
287
299
|
async getNode(uid) {
|
|
288
|
-
return this.get(`/node/${uid}`);
|
|
300
|
+
return this.get(`/node/${seg(uid)}`);
|
|
289
301
|
}
|
|
290
302
|
/**
|
|
291
303
|
* Create a node via the low-level CRUD endpoint.
|
|
@@ -302,10 +314,10 @@ var MindGraph = class {
|
|
|
302
314
|
return this.post("/node", { ...body, props });
|
|
303
315
|
}
|
|
304
316
|
async updateNode(uid, body) {
|
|
305
|
-
return this.patch(`/node/${uid}`, body);
|
|
317
|
+
return this.patch(`/node/${seg(uid)}`, body);
|
|
306
318
|
}
|
|
307
319
|
async deleteNode(uid) {
|
|
308
|
-
await this.del(`/node/${uid}`);
|
|
320
|
+
await this.del(`/node/${seg(uid)}`);
|
|
309
321
|
}
|
|
310
322
|
async batchDeleteNodes(params) {
|
|
311
323
|
const body = {};
|
|
@@ -326,10 +338,10 @@ var MindGraph = class {
|
|
|
326
338
|
return this.post("/nodes/delete", body);
|
|
327
339
|
}
|
|
328
340
|
async getNodeHistory(uid) {
|
|
329
|
-
return this.get(`/node/${uid}/history`);
|
|
341
|
+
return this.get(`/node/${seg(uid)}/history`);
|
|
330
342
|
}
|
|
331
343
|
async getNodeAtVersion(uid, version) {
|
|
332
|
-
return this.get(`/node/${uid}/history/${version}`);
|
|
344
|
+
return this.get(`/node/${seg(uid)}/history/${seg(version)}`);
|
|
333
345
|
}
|
|
334
346
|
// ---- Edge CRUD ----
|
|
335
347
|
async addLink(body) {
|
|
@@ -350,13 +362,13 @@ var MindGraph = class {
|
|
|
350
362
|
return this.post("/edge", { ...body, props });
|
|
351
363
|
}
|
|
352
364
|
async updateEdge(uid, body) {
|
|
353
|
-
return this.patch(`/edge/${uid}`, body);
|
|
365
|
+
return this.patch(`/edge/${seg(uid)}`, body);
|
|
354
366
|
}
|
|
355
367
|
async deleteEdge(uid) {
|
|
356
|
-
await this.del(`/edge/${uid}`);
|
|
368
|
+
await this.del(`/edge/${seg(uid)}`);
|
|
357
369
|
}
|
|
358
370
|
async getEdgeHistory(uid) {
|
|
359
|
-
return this.get(`/edge/${uid}/history`);
|
|
371
|
+
return this.get(`/edge/${seg(uid)}/history`);
|
|
360
372
|
}
|
|
361
373
|
/**
|
|
362
374
|
* List edges filtered by source and/or target node.
|
|
@@ -405,7 +417,7 @@ var MindGraph = class {
|
|
|
405
417
|
return this.get(`/nodes?${qs}`);
|
|
406
418
|
}
|
|
407
419
|
async getAgentNodes(agentId) {
|
|
408
|
-
return this.get(`/agent/${agentId}/nodes`);
|
|
420
|
+
return this.get(`/agent/${seg(agentId)}/nodes`);
|
|
409
421
|
}
|
|
410
422
|
// ---- Batch ----
|
|
411
423
|
async batch(req) {
|
|
@@ -430,13 +442,13 @@ var MindGraph = class {
|
|
|
430
442
|
return this.post("/embeddings/search-text", body);
|
|
431
443
|
}
|
|
432
444
|
async getEmbedding(uid) {
|
|
433
|
-
return this.get(`/node/${uid}/embedding`);
|
|
445
|
+
return this.get(`/node/${seg(uid)}/embedding`);
|
|
434
446
|
}
|
|
435
447
|
async setEmbedding(uid, vector) {
|
|
436
|
-
await this.request("PUT", `/node/${uid}/embedding`, { vector });
|
|
448
|
+
await this.request("PUT", `/node/${seg(uid)}/embedding`, { vector });
|
|
437
449
|
}
|
|
438
450
|
async deleteEmbedding(uid) {
|
|
439
|
-
await this.del(`/node/${uid}/embedding`);
|
|
451
|
+
await this.del(`/node/${seg(uid)}/embedding`);
|
|
440
452
|
}
|
|
441
453
|
// ---- Entity resolution ----
|
|
442
454
|
async mergeEntities(body) {
|
|
@@ -446,7 +458,7 @@ var MindGraph = class {
|
|
|
446
458
|
return this.post("/alias", body);
|
|
447
459
|
}
|
|
448
460
|
async getAliases(uid) {
|
|
449
|
-
return this.get(`/aliases/${uid}`);
|
|
461
|
+
return this.get(`/aliases/${seg(uid)}`);
|
|
450
462
|
}
|
|
451
463
|
async resolveAlias(text) {
|
|
452
464
|
return this.get(`/resolve?text=${encodeURIComponent(text)}`);
|
|
@@ -569,18 +581,18 @@ var MindGraph = class {
|
|
|
569
581
|
return this.get("/jobs");
|
|
570
582
|
}
|
|
571
583
|
async getJob(id) {
|
|
572
|
-
return this.get(`/jobs/${id}`);
|
|
584
|
+
return this.get(`/jobs/${seg(id)}`);
|
|
573
585
|
}
|
|
574
586
|
async cancelJob(id) {
|
|
575
|
-
return this.post(`/jobs/${id}/cancel`, {});
|
|
587
|
+
return this.post(`/jobs/${seg(id)}/cancel`, {});
|
|
576
588
|
}
|
|
577
589
|
/** Resume ingestion of a document that has failed chunks. */
|
|
578
590
|
async resumeDocument(docUid, opts) {
|
|
579
|
-
return this.post(`/ingest/resume/${docUid}`, opts ?? {});
|
|
591
|
+
return this.post(`/ingest/resume/${seg(docUid)}`, opts ?? {});
|
|
580
592
|
}
|
|
581
593
|
/** Delete a document and all its chunks and extracted nodes. */
|
|
582
594
|
async deleteDocument(uid) {
|
|
583
|
-
return this.del(`/ingest/document/${uid}`);
|
|
595
|
+
return this.del(`/ingest/document/${seg(uid)}`);
|
|
584
596
|
}
|
|
585
597
|
async cleanupOrphans() {
|
|
586
598
|
return this.post("/ingest/cleanup", {});
|
|
@@ -604,27 +616,27 @@ var MindGraph = class {
|
|
|
604
616
|
}
|
|
605
617
|
/** Get a single wiki article by UID. */
|
|
606
618
|
async getArticle(uid) {
|
|
607
|
-
return this.get(`/wiki/article/${uid}`);
|
|
619
|
+
return this.get(`/wiki/article/${seg(uid)}`);
|
|
608
620
|
}
|
|
609
621
|
/** Find the article that covers or summarizes a given entity/document UID. */
|
|
610
622
|
async getArticleBySubject(subjectUid) {
|
|
611
623
|
try {
|
|
612
|
-
return await this.get(`/wiki/article/by-subject/${subjectUid}`);
|
|
624
|
+
return await this.get(`/wiki/article/by-subject/${seg(subjectUid)}`);
|
|
613
625
|
} catch {
|
|
614
626
|
return null;
|
|
615
627
|
}
|
|
616
628
|
}
|
|
617
629
|
/** Update an article's markdown content (user editing). */
|
|
618
630
|
async updateArticle(uid, content) {
|
|
619
|
-
return this.patch(`/wiki/article/${uid}`, { content });
|
|
631
|
+
return this.patch(`/wiki/article/${seg(uid)}`, { content });
|
|
620
632
|
}
|
|
621
633
|
/** Trigger wiki compilation for a specific document. */
|
|
622
634
|
async compileDocument(docUid) {
|
|
623
|
-
return this.post(`/wiki/compile/${docUid}`, {});
|
|
635
|
+
return this.post(`/wiki/compile/${seg(docUid)}`, {});
|
|
624
636
|
}
|
|
625
637
|
/** Trigger wiki compilation for a specific entity. */
|
|
626
638
|
async compileEntity(entityUid) {
|
|
627
|
-
return this.post(`/wiki/compile/entity/${entityUid}`, {});
|
|
639
|
+
return this.post(`/wiki/compile/entity/${seg(entityUid)}`, {});
|
|
628
640
|
}
|
|
629
641
|
/** Backfill: compile articles for all documents and eligible entities. */
|
|
630
642
|
async compileAll() {
|
|
@@ -645,7 +657,7 @@ var MindGraph = class {
|
|
|
645
657
|
if (opts?.signals) q.set("signals", opts.signals);
|
|
646
658
|
if (opts?.target_types) q.set("target_types", opts.target_types);
|
|
647
659
|
const qs = q.toString();
|
|
648
|
-
return this.get(`/synthesis/signals/${projectUid}${qs ? `?${qs}` : ""}`);
|
|
660
|
+
return this.get(`/synthesis/signals/${seg(projectUid)}${qs ? `?${qs}` : ""}`);
|
|
649
661
|
}
|
|
650
662
|
/**
|
|
651
663
|
* Spawn a background synthesis job for a project: mines signals,
|
|
@@ -655,7 +667,7 @@ var MindGraph = class {
|
|
|
655
667
|
* Returns a `job_id` immediately; poll `getJob(id)` for progress.
|
|
656
668
|
*/
|
|
657
669
|
async runSynthesis(projectUid) {
|
|
658
|
-
return this.post(`/synthesis/run/${projectUid}`, {});
|
|
670
|
+
return this.post(`/synthesis/run/${seg(projectUid)}`, {});
|
|
659
671
|
}
|
|
660
672
|
// ============================================================================
|
|
661
673
|
// Operational Ontology Layer (Layer 7)
|
|
@@ -665,22 +677,22 @@ var MindGraph = class {
|
|
|
665
677
|
return this.get("/v1/ontology/schemas");
|
|
666
678
|
}
|
|
667
679
|
async getOntologySchema(id) {
|
|
668
|
-
return this.get(`/v1/ontology/schemas/${id}`);
|
|
680
|
+
return this.get(`/v1/ontology/schemas/${seg(id)}`);
|
|
669
681
|
}
|
|
670
682
|
async createOntologySchema(req) {
|
|
671
683
|
return this.post("/v1/ontology/schemas", req);
|
|
672
684
|
}
|
|
673
685
|
async updateOntologySchema(id, req) {
|
|
674
|
-
return this.patch(`/v1/ontology/schemas/${id}`, req);
|
|
686
|
+
return this.patch(`/v1/ontology/schemas/${seg(id)}`, req);
|
|
675
687
|
}
|
|
676
688
|
async activateOntologySchema(id) {
|
|
677
|
-
return this.post(`/v1/ontology/schemas/${id}/activate`, {});
|
|
689
|
+
return this.post(`/v1/ontology/schemas/${seg(id)}/activate`, {});
|
|
678
690
|
}
|
|
679
691
|
async deprecateOntologySchema(id) {
|
|
680
|
-
return this.post(`/v1/ontology/schemas/${id}/deprecate`, {});
|
|
692
|
+
return this.post(`/v1/ontology/schemas/${seg(id)}/deprecate`, {});
|
|
681
693
|
}
|
|
682
694
|
async archiveOntologySchema(id) {
|
|
683
|
-
return this.del(`/v1/ontology/schemas/${id}`);
|
|
695
|
+
return this.del(`/v1/ontology/schemas/${seg(id)}`);
|
|
684
696
|
}
|
|
685
697
|
/**
|
|
686
698
|
* Kick off an LLM-driven schema proposal job.
|
|
@@ -691,47 +703,47 @@ var MindGraph = class {
|
|
|
691
703
|
return this.post("/v1/ontology/propose-schema", req);
|
|
692
704
|
}
|
|
693
705
|
async testOntologySchema(id, opts) {
|
|
694
|
-
return this.post(`/v1/ontology/schemas/${id}/test`, opts ?? {});
|
|
706
|
+
return this.post(`/v1/ontology/schemas/${seg(id)}/test`, opts ?? {});
|
|
695
707
|
}
|
|
696
708
|
// ---- Schema sub-resources ----
|
|
697
709
|
async addOntologyObjectType(schemaId, req) {
|
|
698
|
-
return this.post(`/v1/ontology/schemas/${schemaId}/object-types`, req);
|
|
710
|
+
return this.post(`/v1/ontology/schemas/${seg(schemaId)}/object-types`, req);
|
|
699
711
|
}
|
|
700
712
|
async updateOntologyObjectType(schemaId, typeId, req) {
|
|
701
713
|
return this.patch(
|
|
702
|
-
`/v1/ontology/schemas/${schemaId}/object-types/${typeId}`,
|
|
714
|
+
`/v1/ontology/schemas/${seg(schemaId)}/object-types/${seg(typeId)}`,
|
|
703
715
|
req
|
|
704
716
|
);
|
|
705
717
|
}
|
|
706
718
|
async deleteOntologyObjectType(schemaId, typeId) {
|
|
707
719
|
return this.del(
|
|
708
|
-
`/v1/ontology/schemas/${schemaId}/object-types/${typeId}`
|
|
720
|
+
`/v1/ontology/schemas/${seg(schemaId)}/object-types/${seg(typeId)}`
|
|
709
721
|
);
|
|
710
722
|
}
|
|
711
723
|
async addOntologyRelationType(schemaId, req) {
|
|
712
|
-
return this.post(`/v1/ontology/schemas/${schemaId}/relation-types`, req);
|
|
724
|
+
return this.post(`/v1/ontology/schemas/${seg(schemaId)}/relation-types`, req);
|
|
713
725
|
}
|
|
714
726
|
async updateOntologyRelationType(schemaId, typeId, req) {
|
|
715
727
|
return this.patch(
|
|
716
|
-
`/v1/ontology/schemas/${schemaId}/relation-types/${typeId}`,
|
|
728
|
+
`/v1/ontology/schemas/${seg(schemaId)}/relation-types/${seg(typeId)}`,
|
|
717
729
|
req
|
|
718
730
|
);
|
|
719
731
|
}
|
|
720
732
|
async deleteOntologyRelationType(schemaId, typeId) {
|
|
721
733
|
return this.del(
|
|
722
|
-
`/v1/ontology/schemas/${schemaId}/relation-types/${typeId}`
|
|
734
|
+
`/v1/ontology/schemas/${seg(schemaId)}/relation-types/${seg(typeId)}`
|
|
723
735
|
);
|
|
724
736
|
}
|
|
725
737
|
/** Generate inert semantic classifications for individual human review. */
|
|
726
738
|
async analyzeOntologySemanticGuidance(schemaId) {
|
|
727
739
|
return this.post(
|
|
728
|
-
`/v1/ontology/schemas/${schemaId}/semantic-guidance/analyze`,
|
|
740
|
+
`/v1/ontology/schemas/${seg(schemaId)}/semantic-guidance/analyze`,
|
|
729
741
|
{}
|
|
730
742
|
);
|
|
731
743
|
}
|
|
732
744
|
/** Read-only exact-identity collision audit; never merges graph data. */
|
|
733
745
|
async auditOntologyDuplicates(schemaId) {
|
|
734
|
-
return this.post(`/v1/ontology/schemas/${schemaId}/duplicates/audit`, {});
|
|
746
|
+
return this.post(`/v1/ontology/schemas/${seg(schemaId)}/duplicates/audit`, {});
|
|
735
747
|
}
|
|
736
748
|
// ---- Proposals ----
|
|
737
749
|
async listOntologyProposals(opts) {
|
|
@@ -747,19 +759,19 @@ var MindGraph = class {
|
|
|
747
759
|
return this.get(`/v1/ontology/proposals${qs ? `?${qs}` : ""}`);
|
|
748
760
|
}
|
|
749
761
|
async getOntologyProposal(id) {
|
|
750
|
-
return this.get(`/v1/ontology/proposals/${id}`);
|
|
762
|
+
return this.get(`/v1/ontology/proposals/${seg(id)}`);
|
|
751
763
|
}
|
|
752
764
|
async patchOntologyProposal(id, req) {
|
|
753
|
-
return this.patch(`/v1/ontology/proposals/${id}`, req);
|
|
765
|
+
return this.patch(`/v1/ontology/proposals/${seg(id)}`, req);
|
|
754
766
|
}
|
|
755
767
|
async approveOntologyProposal(id, opts) {
|
|
756
|
-
return this.post(`/v1/ontology/proposals/${id}/approve`, opts ?? {});
|
|
768
|
+
return this.post(`/v1/ontology/proposals/${seg(id)}/approve`, opts ?? {});
|
|
757
769
|
}
|
|
758
770
|
async rejectOntologyProposal(id, reason) {
|
|
759
|
-
return this.post(`/v1/ontology/proposals/${id}/reject`, { reason });
|
|
771
|
+
return this.post(`/v1/ontology/proposals/${seg(id)}/reject`, { reason });
|
|
760
772
|
}
|
|
761
773
|
async applyOntologyProposal(id) {
|
|
762
|
-
return this.post(`/v1/ontology/proposals/${id}/apply`, {});
|
|
774
|
+
return this.post(`/v1/ontology/proposals/${seg(id)}/apply`, {});
|
|
763
775
|
}
|
|
764
776
|
async batchApproveOntologyProposals(ids, feedback) {
|
|
765
777
|
return this.post("/v1/ontology/proposals/batch-approve", { ids, feedback });
|
|
@@ -771,24 +783,58 @@ var MindGraph = class {
|
|
|
771
783
|
async queryOntology(req) {
|
|
772
784
|
return this.post("/ontology/query", req);
|
|
773
785
|
}
|
|
786
|
+
async queryDomainStructured(req) {
|
|
787
|
+
return this.post("/ontology/query/structured", req);
|
|
788
|
+
}
|
|
789
|
+
async queryRelatedDomainObjects(req) {
|
|
790
|
+
return this.queryDomainStructured({
|
|
791
|
+
schema_id: req.schema_id,
|
|
792
|
+
select: req.far_type,
|
|
793
|
+
...req.project_uid ? { project_uid: req.project_uid } : {},
|
|
794
|
+
anchor: { type: req.entry_type, uid: req.uid },
|
|
795
|
+
path: [{
|
|
796
|
+
relation: req.relation,
|
|
797
|
+
entry_role: req.entry_role
|
|
798
|
+
}],
|
|
799
|
+
...req.where ? { where: req.where } : {},
|
|
800
|
+
...req.include_provenance ? { include: { provenance: true } } : {},
|
|
801
|
+
page: {
|
|
802
|
+
...req.limit != null ? { limit: req.limit } : {},
|
|
803
|
+
...req.offset != null ? { offset: req.offset } : {}
|
|
804
|
+
}
|
|
805
|
+
});
|
|
806
|
+
}
|
|
774
807
|
/**
|
|
775
|
-
*
|
|
776
|
-
*
|
|
777
|
-
*
|
|
778
|
-
* tools (`search_customers`, `summarize_customer`, …).
|
|
808
|
+
* Schema-qualified read-tool descriptors generated from every active
|
|
809
|
+
* ontology. Includes per-object discovery/point/context tools,
|
|
810
|
+
* relation-and-role-specific related tools, and one structured composite.
|
|
779
811
|
*/
|
|
780
812
|
async listOntologyTools() {
|
|
781
813
|
return this.get("/v1/ontology/tools");
|
|
782
814
|
}
|
|
783
|
-
async getDomainObject(uid) {
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
815
|
+
async getDomainObject(uid, binding) {
|
|
816
|
+
const query = new URLSearchParams();
|
|
817
|
+
if (binding) {
|
|
818
|
+
query.set("schema_id", binding.schema_id);
|
|
819
|
+
query.set("object_type", binding.object_type);
|
|
820
|
+
if (binding.project_uid) query.set("project_uid", binding.project_uid);
|
|
821
|
+
}
|
|
822
|
+
const suffix = query.size > 0 ? `?${query.toString()}` : "";
|
|
823
|
+
return this.get(`/ontology/object/${seg(uid)}${suffix}`);
|
|
824
|
+
}
|
|
825
|
+
async getDomainObjectContext(uid, depth, binding) {
|
|
826
|
+
const query = new URLSearchParams();
|
|
827
|
+
if (depth != null) query.set("depth", String(depth));
|
|
828
|
+
if (binding) {
|
|
829
|
+
query.set("schema_id", binding.schema_id);
|
|
830
|
+
query.set("object_type", binding.object_type);
|
|
831
|
+
if (binding.project_uid) query.set("project_uid", binding.project_uid);
|
|
832
|
+
}
|
|
833
|
+
const suffix = query.size > 0 ? `?${query.toString()}` : "";
|
|
834
|
+
return this.get(`/ontology/object/${seg(uid)}/context${suffix}`);
|
|
789
835
|
}
|
|
790
836
|
async getDomainObjectHistory(uid) {
|
|
791
|
-
return this.get(`/ontology/object/${uid}/history`);
|
|
837
|
+
return this.get(`/ontology/object/${seg(uid)}/history`);
|
|
792
838
|
}
|
|
793
839
|
async listDomainObjects(opts) {
|
|
794
840
|
const q = new URLSearchParams();
|
|
@@ -828,6 +874,12 @@ var MindGraph = class {
|
|
|
828
874
|
return this.post("/ontology/extract", req);
|
|
829
875
|
}
|
|
830
876
|
};
|
|
877
|
+
function createRequestId() {
|
|
878
|
+
if (typeof globalThis.crypto?.randomUUID === "function") {
|
|
879
|
+
return globalThis.crypto.randomUUID();
|
|
880
|
+
}
|
|
881
|
+
return `${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`;
|
|
882
|
+
}
|
|
831
883
|
export {
|
|
832
884
|
MindGraph,
|
|
833
885
|
MindGraphError
|