mindgraph 0.1.8 → 0.2.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 +21 -1
- package/dist/index.d.mts +96 -1
- package/dist/index.d.ts +96 -1
- package/dist/index.js +87 -16
- package/dist/index.mjs +87 -16
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -52,7 +52,27 @@ new MindGraph({ baseUrl: string, apiKey?: string, jwt?: string })
|
|
|
52
52
|
|--------|-------------|
|
|
53
53
|
| `capture(req)` | Capture a source, snippet, or observation |
|
|
54
54
|
| `entity(req)` | Create, alias, resolve, or merge entities |
|
|
55
|
-
| `findOrCreateEntity(label, entityType?, agentId?)` | Convenience: create or find an entity by label |
|
|
55
|
+
| `findOrCreateEntity(label, entityType?, agentId?)` | Convenience: create or find an entity by label (generic fallback) |
|
|
56
|
+
| `findOrCreatePerson(label, props?, agentId?)` | Find or create a Person entity |
|
|
57
|
+
| `findOrCreateOrganization(label, props?, agentId?)` | Find or create an Organization entity |
|
|
58
|
+
| `findOrCreateNation(label, props?, agentId?)` | Find or create a Nation entity |
|
|
59
|
+
| `findOrCreateEvent(label, props?, agentId?)` | Find or create an Event entity |
|
|
60
|
+
| `findOrCreatePlace(label, props?, agentId?)` | Find or create a Place entity |
|
|
61
|
+
| `findOrCreateConcept(label, props?, agentId?)` | Find or create a Concept entity |
|
|
62
|
+
| `addClaim(label, props?, agentId?)` | Add a Claim node |
|
|
63
|
+
| `addEvidence(label, props?, agentId?)` | Add an Evidence node |
|
|
64
|
+
| `addObservation(label, props?, agentId?)` | Add an Observation node |
|
|
65
|
+
|
|
66
|
+
**Typed entity example:**
|
|
67
|
+
|
|
68
|
+
```typescript
|
|
69
|
+
const person = await graph.findOrCreatePerson("Marie Curie", { nationality: "Polish" });
|
|
70
|
+
const org = await graph.findOrCreateOrganization("CERN", { org_type: "intergovernmental" });
|
|
71
|
+
const concept = await graph.findOrCreateConcept("Nuclear Physics");
|
|
72
|
+
|
|
73
|
+
// findOrCreateEntity() still works as a generic fallback for any entity type
|
|
74
|
+
const entity = await graph.findOrCreateEntity("Some Entity");
|
|
75
|
+
```
|
|
56
76
|
|
|
57
77
|
### Epistemic Layer
|
|
58
78
|
|
package/dist/index.d.mts
CHANGED
|
@@ -38,6 +38,59 @@ interface PathStep {
|
|
|
38
38
|
depth: number;
|
|
39
39
|
parent_uid: string | null;
|
|
40
40
|
}
|
|
41
|
+
interface PersonProps {
|
|
42
|
+
canonical_name: string;
|
|
43
|
+
description?: string;
|
|
44
|
+
birth_date?: string;
|
|
45
|
+
death_date?: string;
|
|
46
|
+
nationality?: string;
|
|
47
|
+
occupation?: string;
|
|
48
|
+
identifiers?: Record<string, string>;
|
|
49
|
+
attributes?: Record<string, unknown>;
|
|
50
|
+
}
|
|
51
|
+
interface OrganizationProps {
|
|
52
|
+
canonical_name: string;
|
|
53
|
+
description?: string;
|
|
54
|
+
org_type: string;
|
|
55
|
+
founded_date?: string;
|
|
56
|
+
dissolved_date?: string;
|
|
57
|
+
headquarters?: string;
|
|
58
|
+
sector?: string;
|
|
59
|
+
identifiers?: Record<string, string>;
|
|
60
|
+
attributes?: Record<string, unknown>;
|
|
61
|
+
}
|
|
62
|
+
interface NationProps {
|
|
63
|
+
canonical_name: string;
|
|
64
|
+
description?: string;
|
|
65
|
+
iso_code?: string;
|
|
66
|
+
capital?: string;
|
|
67
|
+
government_type?: string;
|
|
68
|
+
region?: string;
|
|
69
|
+
identifiers?: Record<string, string>;
|
|
70
|
+
attributes?: Record<string, unknown>;
|
|
71
|
+
}
|
|
72
|
+
interface EventProps {
|
|
73
|
+
canonical_name: string;
|
|
74
|
+
description?: string;
|
|
75
|
+
event_type: string;
|
|
76
|
+
event_date?: string;
|
|
77
|
+
end_date?: string;
|
|
78
|
+
location?: string;
|
|
79
|
+
identifiers?: Record<string, string>;
|
|
80
|
+
attributes?: Record<string, unknown>;
|
|
81
|
+
}
|
|
82
|
+
interface PlaceProps {
|
|
83
|
+
canonical_name: string;
|
|
84
|
+
description?: string;
|
|
85
|
+
place_type: string;
|
|
86
|
+
coordinates?: {
|
|
87
|
+
lat: number;
|
|
88
|
+
lon: number;
|
|
89
|
+
};
|
|
90
|
+
parent_location?: string;
|
|
91
|
+
identifiers?: Record<string, string>;
|
|
92
|
+
attributes?: Record<string, unknown>;
|
|
93
|
+
}
|
|
41
94
|
interface CaptureRequest {
|
|
42
95
|
action: "source" | "snippet" | "observation";
|
|
43
96
|
label: string;
|
|
@@ -413,6 +466,10 @@ interface MindGraphConfig {
|
|
|
413
466
|
baseUrl: string;
|
|
414
467
|
apiKey?: string;
|
|
415
468
|
jwt?: string;
|
|
469
|
+
/** Max retries for 503 (server warming up) responses. Default: 3. Set to 0 to disable. */
|
|
470
|
+
maxRetries?: number;
|
|
471
|
+
/** Initial backoff in ms before first retry. Doubles each attempt. Default: 1000. */
|
|
472
|
+
retryBackoffMs?: number;
|
|
416
473
|
}
|
|
417
474
|
|
|
418
475
|
declare class MindGraphError extends Error {
|
|
@@ -423,6 +480,8 @@ declare class MindGraphError extends Error {
|
|
|
423
480
|
declare class MindGraph {
|
|
424
481
|
private baseUrl;
|
|
425
482
|
private headers;
|
|
483
|
+
private maxRetries;
|
|
484
|
+
private retryBackoffMs;
|
|
426
485
|
constructor(config: MindGraphConfig);
|
|
427
486
|
private request;
|
|
428
487
|
private get;
|
|
@@ -439,6 +498,30 @@ declare class MindGraph {
|
|
|
439
498
|
findOrCreateEntity(label: string, props?: Record<string, unknown>, agentId?: string): Promise<GraphNode & {
|
|
440
499
|
created: boolean;
|
|
441
500
|
}>;
|
|
501
|
+
/** Convenience: create or find a Person entity by label. */
|
|
502
|
+
findOrCreatePerson(label: string, props?: Record<string, unknown>, agentId?: string): Promise<GraphNode & {
|
|
503
|
+
created: boolean;
|
|
504
|
+
}>;
|
|
505
|
+
/** Convenience: create or find an Organization entity by label. */
|
|
506
|
+
findOrCreateOrganization(label: string, props?: Record<string, unknown>, agentId?: string): Promise<GraphNode & {
|
|
507
|
+
created: boolean;
|
|
508
|
+
}>;
|
|
509
|
+
/** Convenience: create or find a Nation entity by label. */
|
|
510
|
+
findOrCreateNation(label: string, props?: Record<string, unknown>, agentId?: string): Promise<GraphNode & {
|
|
511
|
+
created: boolean;
|
|
512
|
+
}>;
|
|
513
|
+
/** Convenience: create or find an Event entity by label. */
|
|
514
|
+
findOrCreateEvent(label: string, props?: Record<string, unknown>, agentId?: string): Promise<GraphNode & {
|
|
515
|
+
created: boolean;
|
|
516
|
+
}>;
|
|
517
|
+
/** Convenience: create or find a Place entity by label. */
|
|
518
|
+
findOrCreatePlace(label: string, props?: Record<string, unknown>, agentId?: string): Promise<GraphNode & {
|
|
519
|
+
created: boolean;
|
|
520
|
+
}>;
|
|
521
|
+
/** Convenience: create or find a Concept entity by label. */
|
|
522
|
+
findOrCreateConcept(label: string, props?: Record<string, unknown>, agentId?: string): Promise<GraphNode & {
|
|
523
|
+
created: boolean;
|
|
524
|
+
}>;
|
|
442
525
|
/**
|
|
443
526
|
* Resolve text to an existing entity via alias matching.
|
|
444
527
|
* Returns `{ uid: string | null }`.
|
|
@@ -460,6 +543,18 @@ declare class MindGraph {
|
|
|
460
543
|
argue(req: ArgumentRequest): Promise<unknown>;
|
|
461
544
|
inquire(req: InquiryRequest): Promise<unknown>;
|
|
462
545
|
structure(req: StructureRequest): Promise<unknown>;
|
|
546
|
+
/**
|
|
547
|
+
* Convenience: create a Claim node via the argument endpoint.
|
|
548
|
+
* Returns the full argument response including `claim_uid`.
|
|
549
|
+
*/
|
|
550
|
+
addClaim(label: string, content: string, confidence?: number, agentId?: string): Promise<unknown>;
|
|
551
|
+
/**
|
|
552
|
+
* Convenience: create an Evidence node attached to a claim via the argument endpoint.
|
|
553
|
+
* If `claimLabel` and `claimConfidence` are provided, also creates the claim.
|
|
554
|
+
*/
|
|
555
|
+
addEvidence(label: string, description: string, agentId?: string): Promise<unknown>;
|
|
556
|
+
/** Convenience: create an Observation node via the reality capture endpoint. */
|
|
557
|
+
addObservation(label: string, description: string, agentId?: string): Promise<unknown>;
|
|
463
558
|
commit(req: CommitmentRequest): Promise<unknown>;
|
|
464
559
|
deliberate(req: DeliberationRequest): Promise<unknown>;
|
|
465
560
|
/** Open a new decision for deliberation. Returns the Decision node. */
|
|
@@ -669,4 +764,4 @@ declare class MindGraph {
|
|
|
669
764
|
clearGraph(): Promise<ClearResponse>;
|
|
670
765
|
}
|
|
671
766
|
|
|
672
|
-
export { type ArgumentRequest, type BatchRequest, type CaptureRequest, type ClearResponse, type CommitmentRequest, type DecayRequest, type DeliberationRequest, type DistillRequest, type EntityRequest, type EvolveRequest, type ExecutionRequest, type GovernanceRequest, type GraphEdge, type GraphNode, type IngestChunkRequest, type IngestChunkResponse, type IngestDocumentRequest, type IngestDocumentResponse, type IngestSessionRequest, type InquiryRequest, type Job, type MemoryConfigRequest, MindGraph, type MindGraphConfig, MindGraphError, type PathStep, type PlanRequest, type ProcedureRequest, type PurgeRequest, type RetrieveContextRequest, type RetrieveContextResponse, type RetrieveRequest, type RiskRequest, type SearchResult, type SessionRequest, type StructureRequest, type TraverseRequest };
|
|
767
|
+
export { type ArgumentRequest, type BatchRequest, type CaptureRequest, type ClearResponse, type CommitmentRequest, type DecayRequest, type DeliberationRequest, type DistillRequest, type EntityRequest, type EventProps, type EvolveRequest, type ExecutionRequest, type GovernanceRequest, type GraphEdge, type GraphNode, type IngestChunkRequest, type IngestChunkResponse, type IngestDocumentRequest, type IngestDocumentResponse, type IngestSessionRequest, type InquiryRequest, type Job, type MemoryConfigRequest, MindGraph, type MindGraphConfig, MindGraphError, type NationProps, type OrganizationProps, type PathStep, type PersonProps, type PlaceProps, type PlanRequest, type ProcedureRequest, type PurgeRequest, type RetrieveContextRequest, type RetrieveContextResponse, type RetrieveRequest, type RiskRequest, type SearchResult, type SessionRequest, type StructureRequest, type TraverseRequest };
|
package/dist/index.d.ts
CHANGED
|
@@ -38,6 +38,59 @@ interface PathStep {
|
|
|
38
38
|
depth: number;
|
|
39
39
|
parent_uid: string | null;
|
|
40
40
|
}
|
|
41
|
+
interface PersonProps {
|
|
42
|
+
canonical_name: string;
|
|
43
|
+
description?: string;
|
|
44
|
+
birth_date?: string;
|
|
45
|
+
death_date?: string;
|
|
46
|
+
nationality?: string;
|
|
47
|
+
occupation?: string;
|
|
48
|
+
identifiers?: Record<string, string>;
|
|
49
|
+
attributes?: Record<string, unknown>;
|
|
50
|
+
}
|
|
51
|
+
interface OrganizationProps {
|
|
52
|
+
canonical_name: string;
|
|
53
|
+
description?: string;
|
|
54
|
+
org_type: string;
|
|
55
|
+
founded_date?: string;
|
|
56
|
+
dissolved_date?: string;
|
|
57
|
+
headquarters?: string;
|
|
58
|
+
sector?: string;
|
|
59
|
+
identifiers?: Record<string, string>;
|
|
60
|
+
attributes?: Record<string, unknown>;
|
|
61
|
+
}
|
|
62
|
+
interface NationProps {
|
|
63
|
+
canonical_name: string;
|
|
64
|
+
description?: string;
|
|
65
|
+
iso_code?: string;
|
|
66
|
+
capital?: string;
|
|
67
|
+
government_type?: string;
|
|
68
|
+
region?: string;
|
|
69
|
+
identifiers?: Record<string, string>;
|
|
70
|
+
attributes?: Record<string, unknown>;
|
|
71
|
+
}
|
|
72
|
+
interface EventProps {
|
|
73
|
+
canonical_name: string;
|
|
74
|
+
description?: string;
|
|
75
|
+
event_type: string;
|
|
76
|
+
event_date?: string;
|
|
77
|
+
end_date?: string;
|
|
78
|
+
location?: string;
|
|
79
|
+
identifiers?: Record<string, string>;
|
|
80
|
+
attributes?: Record<string, unknown>;
|
|
81
|
+
}
|
|
82
|
+
interface PlaceProps {
|
|
83
|
+
canonical_name: string;
|
|
84
|
+
description?: string;
|
|
85
|
+
place_type: string;
|
|
86
|
+
coordinates?: {
|
|
87
|
+
lat: number;
|
|
88
|
+
lon: number;
|
|
89
|
+
};
|
|
90
|
+
parent_location?: string;
|
|
91
|
+
identifiers?: Record<string, string>;
|
|
92
|
+
attributes?: Record<string, unknown>;
|
|
93
|
+
}
|
|
41
94
|
interface CaptureRequest {
|
|
42
95
|
action: "source" | "snippet" | "observation";
|
|
43
96
|
label: string;
|
|
@@ -413,6 +466,10 @@ interface MindGraphConfig {
|
|
|
413
466
|
baseUrl: string;
|
|
414
467
|
apiKey?: string;
|
|
415
468
|
jwt?: string;
|
|
469
|
+
/** Max retries for 503 (server warming up) responses. Default: 3. Set to 0 to disable. */
|
|
470
|
+
maxRetries?: number;
|
|
471
|
+
/** Initial backoff in ms before first retry. Doubles each attempt. Default: 1000. */
|
|
472
|
+
retryBackoffMs?: number;
|
|
416
473
|
}
|
|
417
474
|
|
|
418
475
|
declare class MindGraphError extends Error {
|
|
@@ -423,6 +480,8 @@ declare class MindGraphError extends Error {
|
|
|
423
480
|
declare class MindGraph {
|
|
424
481
|
private baseUrl;
|
|
425
482
|
private headers;
|
|
483
|
+
private maxRetries;
|
|
484
|
+
private retryBackoffMs;
|
|
426
485
|
constructor(config: MindGraphConfig);
|
|
427
486
|
private request;
|
|
428
487
|
private get;
|
|
@@ -439,6 +498,30 @@ declare class MindGraph {
|
|
|
439
498
|
findOrCreateEntity(label: string, props?: Record<string, unknown>, agentId?: string): Promise<GraphNode & {
|
|
440
499
|
created: boolean;
|
|
441
500
|
}>;
|
|
501
|
+
/** Convenience: create or find a Person entity by label. */
|
|
502
|
+
findOrCreatePerson(label: string, props?: Record<string, unknown>, agentId?: string): Promise<GraphNode & {
|
|
503
|
+
created: boolean;
|
|
504
|
+
}>;
|
|
505
|
+
/** Convenience: create or find an Organization entity by label. */
|
|
506
|
+
findOrCreateOrganization(label: string, props?: Record<string, unknown>, agentId?: string): Promise<GraphNode & {
|
|
507
|
+
created: boolean;
|
|
508
|
+
}>;
|
|
509
|
+
/** Convenience: create or find a Nation entity by label. */
|
|
510
|
+
findOrCreateNation(label: string, props?: Record<string, unknown>, agentId?: string): Promise<GraphNode & {
|
|
511
|
+
created: boolean;
|
|
512
|
+
}>;
|
|
513
|
+
/** Convenience: create or find an Event entity by label. */
|
|
514
|
+
findOrCreateEvent(label: string, props?: Record<string, unknown>, agentId?: string): Promise<GraphNode & {
|
|
515
|
+
created: boolean;
|
|
516
|
+
}>;
|
|
517
|
+
/** Convenience: create or find a Place entity by label. */
|
|
518
|
+
findOrCreatePlace(label: string, props?: Record<string, unknown>, agentId?: string): Promise<GraphNode & {
|
|
519
|
+
created: boolean;
|
|
520
|
+
}>;
|
|
521
|
+
/** Convenience: create or find a Concept entity by label. */
|
|
522
|
+
findOrCreateConcept(label: string, props?: Record<string, unknown>, agentId?: string): Promise<GraphNode & {
|
|
523
|
+
created: boolean;
|
|
524
|
+
}>;
|
|
442
525
|
/**
|
|
443
526
|
* Resolve text to an existing entity via alias matching.
|
|
444
527
|
* Returns `{ uid: string | null }`.
|
|
@@ -460,6 +543,18 @@ declare class MindGraph {
|
|
|
460
543
|
argue(req: ArgumentRequest): Promise<unknown>;
|
|
461
544
|
inquire(req: InquiryRequest): Promise<unknown>;
|
|
462
545
|
structure(req: StructureRequest): Promise<unknown>;
|
|
546
|
+
/**
|
|
547
|
+
* Convenience: create a Claim node via the argument endpoint.
|
|
548
|
+
* Returns the full argument response including `claim_uid`.
|
|
549
|
+
*/
|
|
550
|
+
addClaim(label: string, content: string, confidence?: number, agentId?: string): Promise<unknown>;
|
|
551
|
+
/**
|
|
552
|
+
* Convenience: create an Evidence node attached to a claim via the argument endpoint.
|
|
553
|
+
* If `claimLabel` and `claimConfidence` are provided, also creates the claim.
|
|
554
|
+
*/
|
|
555
|
+
addEvidence(label: string, description: string, agentId?: string): Promise<unknown>;
|
|
556
|
+
/** Convenience: create an Observation node via the reality capture endpoint. */
|
|
557
|
+
addObservation(label: string, description: string, agentId?: string): Promise<unknown>;
|
|
463
558
|
commit(req: CommitmentRequest): Promise<unknown>;
|
|
464
559
|
deliberate(req: DeliberationRequest): Promise<unknown>;
|
|
465
560
|
/** Open a new decision for deliberation. Returns the Decision node. */
|
|
@@ -669,4 +764,4 @@ declare class MindGraph {
|
|
|
669
764
|
clearGraph(): Promise<ClearResponse>;
|
|
670
765
|
}
|
|
671
766
|
|
|
672
|
-
export { type ArgumentRequest, type BatchRequest, type CaptureRequest, type ClearResponse, type CommitmentRequest, type DecayRequest, type DeliberationRequest, type DistillRequest, type EntityRequest, type EvolveRequest, type ExecutionRequest, type GovernanceRequest, type GraphEdge, type GraphNode, type IngestChunkRequest, type IngestChunkResponse, type IngestDocumentRequest, type IngestDocumentResponse, type IngestSessionRequest, type InquiryRequest, type Job, type MemoryConfigRequest, MindGraph, type MindGraphConfig, MindGraphError, type PathStep, type PlanRequest, type ProcedureRequest, type PurgeRequest, type RetrieveContextRequest, type RetrieveContextResponse, type RetrieveRequest, type RiskRequest, type SearchResult, type SessionRequest, type StructureRequest, type TraverseRequest };
|
|
767
|
+
export { type ArgumentRequest, type BatchRequest, type CaptureRequest, type ClearResponse, type CommitmentRequest, type DecayRequest, type DeliberationRequest, type DistillRequest, type EntityRequest, type EventProps, type EvolveRequest, type ExecutionRequest, type GovernanceRequest, type GraphEdge, type GraphNode, type IngestChunkRequest, type IngestChunkResponse, type IngestDocumentRequest, type IngestDocumentResponse, type IngestSessionRequest, type InquiryRequest, type Job, type MemoryConfigRequest, MindGraph, type MindGraphConfig, MindGraphError, type NationProps, type OrganizationProps, type PathStep, type PersonProps, type PlaceProps, type PlanRequest, type ProcedureRequest, type PurgeRequest, type RetrieveContextRequest, type RetrieveContextResponse, type RetrieveRequest, type RiskRequest, type SearchResult, type SessionRequest, type StructureRequest, type TraverseRequest };
|
package/dist/index.js
CHANGED
|
@@ -43,6 +43,8 @@ var MindGraph = class {
|
|
|
43
43
|
} else if (config.jwt) {
|
|
44
44
|
this.headers["Authorization"] = `Bearer ${config.jwt}`;
|
|
45
45
|
}
|
|
46
|
+
this.maxRetries = config.maxRetries ?? 3;
|
|
47
|
+
this.retryBackoffMs = config.retryBackoffMs ?? 1e3;
|
|
46
48
|
}
|
|
47
49
|
// ---- HTTP helpers ----
|
|
48
50
|
async request(method, path, body) {
|
|
@@ -54,24 +56,35 @@ var MindGraph = class {
|
|
|
54
56
|
if (body !== void 0) {
|
|
55
57
|
init.body = JSON.stringify(body);
|
|
56
58
|
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
const
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
parsed
|
|
63
|
-
|
|
64
|
-
|
|
59
|
+
let lastError;
|
|
60
|
+
for (let attempt = 0; attempt <= this.maxRetries; attempt++) {
|
|
61
|
+
const res = await fetch(url, init);
|
|
62
|
+
if (!res.ok) {
|
|
63
|
+
const text2 = await res.text().catch(() => "");
|
|
64
|
+
let parsed;
|
|
65
|
+
try {
|
|
66
|
+
parsed = JSON.parse(text2);
|
|
67
|
+
} catch {
|
|
68
|
+
parsed = text2;
|
|
69
|
+
}
|
|
70
|
+
const err = new MindGraphError(
|
|
71
|
+
`${method} ${path} failed: ${res.status}`,
|
|
72
|
+
res.status,
|
|
73
|
+
parsed
|
|
74
|
+
);
|
|
75
|
+
if (res.status === 503 && attempt < this.maxRetries) {
|
|
76
|
+
lastError = err;
|
|
77
|
+
const delay = this.retryBackoffMs * 2 ** attempt;
|
|
78
|
+
await new Promise((r) => setTimeout(r, delay));
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
81
|
+
throw err;
|
|
65
82
|
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
parsed
|
|
70
|
-
);
|
|
83
|
+
const text = await res.text();
|
|
84
|
+
if (!text) return void 0;
|
|
85
|
+
return JSON.parse(text);
|
|
71
86
|
}
|
|
72
|
-
|
|
73
|
-
if (!text) return void 0;
|
|
74
|
-
return JSON.parse(text);
|
|
87
|
+
throw lastError;
|
|
75
88
|
}
|
|
76
89
|
get(path) {
|
|
77
90
|
return this.request("GET", path);
|
|
@@ -108,6 +121,30 @@ var MindGraph = class {
|
|
|
108
121
|
agent_id: agentId
|
|
109
122
|
});
|
|
110
123
|
}
|
|
124
|
+
/** Convenience: create or find a Person entity by label. */
|
|
125
|
+
async findOrCreatePerson(label, props, agentId) {
|
|
126
|
+
return this.findOrCreateEntity(label, { entity_type: "person", ...props }, agentId);
|
|
127
|
+
}
|
|
128
|
+
/** Convenience: create or find an Organization entity by label. */
|
|
129
|
+
async findOrCreateOrganization(label, props, agentId) {
|
|
130
|
+
return this.findOrCreateEntity(label, { entity_type: "organization", ...props }, agentId);
|
|
131
|
+
}
|
|
132
|
+
/** Convenience: create or find a Nation entity by label. */
|
|
133
|
+
async findOrCreateNation(label, props, agentId) {
|
|
134
|
+
return this.findOrCreateEntity(label, { entity_type: "nation", ...props }, agentId);
|
|
135
|
+
}
|
|
136
|
+
/** Convenience: create or find an Event entity by label. */
|
|
137
|
+
async findOrCreateEvent(label, props, agentId) {
|
|
138
|
+
return this.findOrCreateEntity(label, { entity_type: "event", ...props }, agentId);
|
|
139
|
+
}
|
|
140
|
+
/** Convenience: create or find a Place entity by label. */
|
|
141
|
+
async findOrCreatePlace(label, props, agentId) {
|
|
142
|
+
return this.findOrCreateEntity(label, { entity_type: "place", ...props }, agentId);
|
|
143
|
+
}
|
|
144
|
+
/** Convenience: create or find a Concept entity by label. */
|
|
145
|
+
async findOrCreateConcept(label, props, agentId) {
|
|
146
|
+
return this.findOrCreateEntity(label, { entity_type: "concept", ...props }, agentId);
|
|
147
|
+
}
|
|
111
148
|
/**
|
|
112
149
|
* Resolve text to an existing entity via alias matching.
|
|
113
150
|
* Returns `{ uid: string | null }`.
|
|
@@ -141,6 +178,40 @@ var MindGraph = class {
|
|
|
141
178
|
async structure(req) {
|
|
142
179
|
return this.post("/epistemic/structure", req);
|
|
143
180
|
}
|
|
181
|
+
/**
|
|
182
|
+
* Convenience: create a Claim node via the argument endpoint.
|
|
183
|
+
* Returns the full argument response including `claim_uid`.
|
|
184
|
+
*/
|
|
185
|
+
async addClaim(label, content, confidence, agentId) {
|
|
186
|
+
return this.post("/epistemic/argument", {
|
|
187
|
+
claim: {
|
|
188
|
+
label,
|
|
189
|
+
confidence,
|
|
190
|
+
props: { content }
|
|
191
|
+
},
|
|
192
|
+
agent_id: agentId
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Convenience: create an Evidence node attached to a claim via the argument endpoint.
|
|
197
|
+
* If `claimLabel` and `claimConfidence` are provided, also creates the claim.
|
|
198
|
+
*/
|
|
199
|
+
async addEvidence(label, description, agentId) {
|
|
200
|
+
return this.post("/epistemic/argument", {
|
|
201
|
+
claim: { label: `Claim for: ${label}` },
|
|
202
|
+
evidence: [{ label, props: { description } }],
|
|
203
|
+
agent_id: agentId
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
/** Convenience: create an Observation node via the reality capture endpoint. */
|
|
207
|
+
async addObservation(label, description, agentId) {
|
|
208
|
+
return this.post("/reality/capture", {
|
|
209
|
+
action: "observation",
|
|
210
|
+
label,
|
|
211
|
+
summary: description,
|
|
212
|
+
agent_id: agentId
|
|
213
|
+
});
|
|
214
|
+
}
|
|
144
215
|
// ---- Intent Layer ----
|
|
145
216
|
async commit(req) {
|
|
146
217
|
return this.post("/intent/commitment", req);
|
package/dist/index.mjs
CHANGED
|
@@ -16,6 +16,8 @@ var MindGraph = class {
|
|
|
16
16
|
} else if (config.jwt) {
|
|
17
17
|
this.headers["Authorization"] = `Bearer ${config.jwt}`;
|
|
18
18
|
}
|
|
19
|
+
this.maxRetries = config.maxRetries ?? 3;
|
|
20
|
+
this.retryBackoffMs = config.retryBackoffMs ?? 1e3;
|
|
19
21
|
}
|
|
20
22
|
// ---- HTTP helpers ----
|
|
21
23
|
async request(method, path, body) {
|
|
@@ -27,24 +29,35 @@ var MindGraph = class {
|
|
|
27
29
|
if (body !== void 0) {
|
|
28
30
|
init.body = JSON.stringify(body);
|
|
29
31
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
parsed
|
|
36
|
-
|
|
37
|
-
|
|
32
|
+
let lastError;
|
|
33
|
+
for (let attempt = 0; attempt <= this.maxRetries; attempt++) {
|
|
34
|
+
const res = await fetch(url, init);
|
|
35
|
+
if (!res.ok) {
|
|
36
|
+
const text2 = await res.text().catch(() => "");
|
|
37
|
+
let parsed;
|
|
38
|
+
try {
|
|
39
|
+
parsed = JSON.parse(text2);
|
|
40
|
+
} catch {
|
|
41
|
+
parsed = text2;
|
|
42
|
+
}
|
|
43
|
+
const err = new MindGraphError(
|
|
44
|
+
`${method} ${path} failed: ${res.status}`,
|
|
45
|
+
res.status,
|
|
46
|
+
parsed
|
|
47
|
+
);
|
|
48
|
+
if (res.status === 503 && attempt < this.maxRetries) {
|
|
49
|
+
lastError = err;
|
|
50
|
+
const delay = this.retryBackoffMs * 2 ** attempt;
|
|
51
|
+
await new Promise((r) => setTimeout(r, delay));
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
54
|
+
throw err;
|
|
38
55
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
parsed
|
|
43
|
-
);
|
|
56
|
+
const text = await res.text();
|
|
57
|
+
if (!text) return void 0;
|
|
58
|
+
return JSON.parse(text);
|
|
44
59
|
}
|
|
45
|
-
|
|
46
|
-
if (!text) return void 0;
|
|
47
|
-
return JSON.parse(text);
|
|
60
|
+
throw lastError;
|
|
48
61
|
}
|
|
49
62
|
get(path) {
|
|
50
63
|
return this.request("GET", path);
|
|
@@ -81,6 +94,30 @@ var MindGraph = class {
|
|
|
81
94
|
agent_id: agentId
|
|
82
95
|
});
|
|
83
96
|
}
|
|
97
|
+
/** Convenience: create or find a Person entity by label. */
|
|
98
|
+
async findOrCreatePerson(label, props, agentId) {
|
|
99
|
+
return this.findOrCreateEntity(label, { entity_type: "person", ...props }, agentId);
|
|
100
|
+
}
|
|
101
|
+
/** Convenience: create or find an Organization entity by label. */
|
|
102
|
+
async findOrCreateOrganization(label, props, agentId) {
|
|
103
|
+
return this.findOrCreateEntity(label, { entity_type: "organization", ...props }, agentId);
|
|
104
|
+
}
|
|
105
|
+
/** Convenience: create or find a Nation entity by label. */
|
|
106
|
+
async findOrCreateNation(label, props, agentId) {
|
|
107
|
+
return this.findOrCreateEntity(label, { entity_type: "nation", ...props }, agentId);
|
|
108
|
+
}
|
|
109
|
+
/** Convenience: create or find an Event entity by label. */
|
|
110
|
+
async findOrCreateEvent(label, props, agentId) {
|
|
111
|
+
return this.findOrCreateEntity(label, { entity_type: "event", ...props }, agentId);
|
|
112
|
+
}
|
|
113
|
+
/** Convenience: create or find a Place entity by label. */
|
|
114
|
+
async findOrCreatePlace(label, props, agentId) {
|
|
115
|
+
return this.findOrCreateEntity(label, { entity_type: "place", ...props }, agentId);
|
|
116
|
+
}
|
|
117
|
+
/** Convenience: create or find a Concept entity by label. */
|
|
118
|
+
async findOrCreateConcept(label, props, agentId) {
|
|
119
|
+
return this.findOrCreateEntity(label, { entity_type: "concept", ...props }, agentId);
|
|
120
|
+
}
|
|
84
121
|
/**
|
|
85
122
|
* Resolve text to an existing entity via alias matching.
|
|
86
123
|
* Returns `{ uid: string | null }`.
|
|
@@ -114,6 +151,40 @@ var MindGraph = class {
|
|
|
114
151
|
async structure(req) {
|
|
115
152
|
return this.post("/epistemic/structure", req);
|
|
116
153
|
}
|
|
154
|
+
/**
|
|
155
|
+
* Convenience: create a Claim node via the argument endpoint.
|
|
156
|
+
* Returns the full argument response including `claim_uid`.
|
|
157
|
+
*/
|
|
158
|
+
async addClaim(label, content, confidence, agentId) {
|
|
159
|
+
return this.post("/epistemic/argument", {
|
|
160
|
+
claim: {
|
|
161
|
+
label,
|
|
162
|
+
confidence,
|
|
163
|
+
props: { content }
|
|
164
|
+
},
|
|
165
|
+
agent_id: agentId
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Convenience: create an Evidence node attached to a claim via the argument endpoint.
|
|
170
|
+
* If `claimLabel` and `claimConfidence` are provided, also creates the claim.
|
|
171
|
+
*/
|
|
172
|
+
async addEvidence(label, description, agentId) {
|
|
173
|
+
return this.post("/epistemic/argument", {
|
|
174
|
+
claim: { label: `Claim for: ${label}` },
|
|
175
|
+
evidence: [{ label, props: { description } }],
|
|
176
|
+
agent_id: agentId
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
/** Convenience: create an Observation node via the reality capture endpoint. */
|
|
180
|
+
async addObservation(label, description, agentId) {
|
|
181
|
+
return this.post("/reality/capture", {
|
|
182
|
+
action: "observation",
|
|
183
|
+
label,
|
|
184
|
+
summary: description,
|
|
185
|
+
agent_id: agentId
|
|
186
|
+
});
|
|
187
|
+
}
|
|
117
188
|
// ---- Intent Layer ----
|
|
118
189
|
async commit(req) {
|
|
119
190
|
return this.post("/intent/commitment", req);
|