@greenlandai/sdk 0.5.14 → 0.5.15
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/CHANGELOG.md +8 -0
- package/dist/index.cjs +50 -10
- package/index.js +2 -2
- package/package.json +1 -1
- package/src/core/errors.js +9 -0
- package/src/core/transport.js +23 -1
- package/src/gldai.js +12 -9
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
## 0.5.15 (2026-10-01)
|
|
2
|
+
- **GreenlandAI's graph answers are about ONE entity** (GreenlandAI 8c0ec77). `client.gldai.relationships()` takes `entityType`
|
|
3
|
+
("company" | "infrastructure" | "deposit" | "project") + `entityId` to pin the start node; `entity` resolves to the one entity
|
|
4
|
+
whose name equals it, else the one whose name contains it. Until 2026-10-01 the server merged every entity whose name contained
|
|
5
|
+
the term into one answer (two plants sharing a name came back as one); it now refuses: several matches throw the new
|
|
6
|
+
`AmbiguousEntityError` (a `ConflictError`; HTTP 409, `.jouleCost` 0, not retried) whose `.candidates` are
|
|
7
|
+
`[{entity_type, entity_id, name, country}]` — call again with one. Every answer carries `resolved`.
|
|
8
|
+
|
|
1
9
|
## 0.5.14 (2026-09-30)
|
|
2
10
|
- **`client.enyal.createAgreement()` on a zero-knowledge account** — ENYAL (6961c0e) refuses it with an uncharged 409; it now
|
|
3
11
|
throws `ProofRefusedError` (`.jouleCost 0`, not retried) like the other uncharged refusals, instead of a plain `ConflictError`.
|
package/dist/index.cjs
CHANGED
|
@@ -19,6 +19,7 @@ var __toCommonJS = (mod2) => __copyProps(__defProp({}, "__esModule", { value: tr
|
|
|
19
19
|
// index.js
|
|
20
20
|
var js_exports = {};
|
|
21
21
|
__export(js_exports, {
|
|
22
|
+
AmbiguousEntityError: () => AmbiguousEntityError,
|
|
22
23
|
AuthError: () => AuthError,
|
|
23
24
|
Client: () => Client,
|
|
24
25
|
ConflictError: () => ConflictError,
|
|
@@ -66,6 +67,13 @@ var ProofRefusedError = class extends ConflictError {
|
|
|
66
67
|
this.jouleCost = 0;
|
|
67
68
|
}
|
|
68
69
|
};
|
|
70
|
+
var AmbiguousEntityError = class extends ConflictError {
|
|
71
|
+
constructor(statusCode, detail, requestId = null, candidates = []) {
|
|
72
|
+
super(statusCode, detail, requestId);
|
|
73
|
+
this.jouleCost = 0;
|
|
74
|
+
this.candidates = [...candidates || []];
|
|
75
|
+
}
|
|
76
|
+
};
|
|
69
77
|
var RateLimitError = class extends GreenlandAIError {
|
|
70
78
|
};
|
|
71
79
|
var ServerError = class extends GreenlandAIError {
|
|
@@ -192,6 +200,26 @@ var PROOF_REFUSAL_PATHS = /* @__PURE__ */ new Set([
|
|
|
192
200
|
"/api/v1/agreement/verify",
|
|
193
201
|
"/api/v1/agreement/create"
|
|
194
202
|
]);
|
|
203
|
+
var ONE_ENTITY_PATHS = /* @__PURE__ */ new Set([
|
|
204
|
+
"/api/v1/relationships",
|
|
205
|
+
"/api/v1/relationships/graph",
|
|
206
|
+
"/api/v1/relationships/path",
|
|
207
|
+
"/api/v1/relationships/subgraph",
|
|
208
|
+
"/api/v1/relationships/cascade"
|
|
209
|
+
]);
|
|
210
|
+
function ambiguousCandidates(err) {
|
|
211
|
+
let d = err.detail;
|
|
212
|
+
if (typeof d === "string") {
|
|
213
|
+
try {
|
|
214
|
+
d = JSON.parse(d);
|
|
215
|
+
} catch {
|
|
216
|
+
return null;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
if (!d || typeof d !== "object" || d.error !== "ambiguous_entity") return null;
|
|
220
|
+
if ("candidates" in d) return d.candidates || [];
|
|
221
|
+
return (d.ambiguous || []).flatMap((a) => a.candidates || []);
|
|
222
|
+
}
|
|
195
223
|
function isRetryable(err) {
|
|
196
224
|
if (err instanceof ConflictError && err.retryAfter != null) return true;
|
|
197
225
|
return err instanceof NetworkError || err instanceof RateLimitError || err instanceof ServerError;
|
|
@@ -284,6 +312,14 @@ var Transport = class {
|
|
|
284
312
|
refused.cause = err;
|
|
285
313
|
throw refused;
|
|
286
314
|
}
|
|
315
|
+
if (err.constructor === ConflictError && err.retryAfter == null && ONE_ENTITY_PATHS.has(pathTemplate)) {
|
|
316
|
+
const cands = ambiguousCandidates(err);
|
|
317
|
+
if (cands !== null) {
|
|
318
|
+
const amb = new AmbiguousEntityError(err.statusCode, err.detail, err.requestId, cands);
|
|
319
|
+
amb.cause = err;
|
|
320
|
+
throw amb;
|
|
321
|
+
}
|
|
322
|
+
}
|
|
287
323
|
throw err;
|
|
288
324
|
}
|
|
289
325
|
let delay = Math.min(DEFAULT_INITIAL_DELAY * DEFAULT_BACKOFF_FACTOR ** attempt, DEFAULT_MAX_DELAY) + DEFAULT_JITTER_MIN + Math.random() * (DEFAULT_JITTER_MAX - DEFAULT_JITTER_MIN);
|
|
@@ -4228,17 +4264,20 @@ var GldaiSubmodule = class {
|
|
|
4228
4264
|
if (entityType != null) params.entity_type = entityType;
|
|
4229
4265
|
return this._t.request(this._base, "GET", "/api/v1/nearby", { params, idempotencyKey });
|
|
4230
4266
|
}
|
|
4231
|
-
/** GET /api/v1/relationships — labelled relationship hops (the MCP `hops` tool).
|
|
4232
|
-
*
|
|
4233
|
-
*
|
|
4234
|
-
*
|
|
4235
|
-
*
|
|
4236
|
-
*
|
|
4237
|
-
*
|
|
4238
|
-
*
|
|
4239
|
-
|
|
4267
|
+
/** GET /api/v1/relationships — labelled relationship hops (the MCP `hops` tool). The answer is about ONE entity (GreenlandAI
|
|
4268
|
+
* 2026-10-01): pin it with entityType ("company" | "infrastructure" | "deposit" | "project") + entityId, or pass `entity` — the
|
|
4269
|
+
* one entity whose name equals it (case-insensitive), else the one whose name contains it. If several match, this throws
|
|
4270
|
+
* AmbiguousEntityError (a 409, nothing charged) whose `.candidates` are [{entity_type, entity_id, name, country}] — call again
|
|
4271
|
+
* with one. The response's `resolved` names the entity the answer is about. `hops` = depth 1-10. relationType (one relation
|
|
4272
|
+
* label, e.g. OPERATES, CONTAINS, MEMBER_OF) is checked against the API's allow-list on BOTH paths (with or without entity): an
|
|
4273
|
+
* unknown label is a 400 naming the allowed set, BEFORE any charge. Metered per hop against the CALLING agent's wallet (quote
|
|
4274
|
+
* with billingQuote("/api/v1/relationships", n)): the response carries charged_joules (the settled all-in — 0 for an empty
|
|
4275
|
+
* result) + the metering block (file header). */
|
|
4276
|
+
relationships({ entity, hops = 1, relationType, search, limit = 50, offset = 0, entityType, entityId, idempotencyKey } = {}) {
|
|
4240
4277
|
const params = { hops, limit, offset };
|
|
4241
4278
|
if (entity) params.entity = entity;
|
|
4279
|
+
if (entityType) params.entity_type = entityType;
|
|
4280
|
+
if (entityId != null && entityId !== "") params.entity_id = entityId;
|
|
4242
4281
|
if (relationType) params.relation_type = relationType;
|
|
4243
4282
|
if (search) params.search = search;
|
|
4244
4283
|
return this._t.request(this._base, "GET", "/api/v1/relationships", { params, idempotencyKey });
|
|
@@ -4889,7 +4928,7 @@ var RareeaiSubmodule = class _RareeaiSubmodule {
|
|
|
4889
4928
|
};
|
|
4890
4929
|
|
|
4891
4930
|
// index.js
|
|
4892
|
-
var VERSION = "0.5.
|
|
4931
|
+
var VERSION = "0.5.15";
|
|
4893
4932
|
var Client = class {
|
|
4894
4933
|
/**
|
|
4895
4934
|
* @param {object} opts
|
|
@@ -4931,6 +4970,7 @@ var Client = class {
|
|
|
4931
4970
|
};
|
|
4932
4971
|
// Annotate the CommonJS export names for ESM import in node:
|
|
4933
4972
|
0 && (module.exports = {
|
|
4973
|
+
AmbiguousEntityError,
|
|
4934
4974
|
AuthError,
|
|
4935
4975
|
Client,
|
|
4936
4976
|
ConflictError,
|
package/index.js
CHANGED
|
@@ -11,12 +11,12 @@ import { GldaiSubmodule, GLDAI_BASE } from "./src/gldai.js";
|
|
|
11
11
|
|
|
12
12
|
export {
|
|
13
13
|
GreenlandAIError, AuthError, ScopeError, NotFoundError, ValidationError,
|
|
14
|
-
ConflictError, ProofRefusedError, RateLimitError, ServerError, NetworkError,
|
|
14
|
+
ConflictError, ProofRefusedError, AmbiguousEntityError, RateLimitError, ServerError, NetworkError,
|
|
15
15
|
} from "./src/core/errors.js";
|
|
16
16
|
export { ENFORCED, NOT_SUPPORTED, SAFE, IDEMPOTENCY_MAP } from "./src/core/idempotency.js";
|
|
17
17
|
export * as crypto from "./src/core/crypto.js";
|
|
18
18
|
|
|
19
|
-
export const VERSION = "0.5.
|
|
19
|
+
export const VERSION = "0.5.15";
|
|
20
20
|
|
|
21
21
|
export class Client {
|
|
22
22
|
/**
|
package/package.json
CHANGED
package/src/core/errors.js
CHANGED
|
@@ -21,6 +21,15 @@ export class ConflictError extends GreenlandAIError {}
|
|
|
21
21
|
export class ProofRefusedError extends ConflictError {
|
|
22
22
|
constructor(statusCode, detail, requestId = null) { super(statusCode, detail, requestId); this.jouleCost = 0; }
|
|
23
23
|
}
|
|
24
|
+
/** 409 — a GreenlandAI graph route (relationships, and the /relationships/graph · path · subgraph · cascade routes) refused to
|
|
25
|
+
* guess between several entities matching the name you gave (GreenlandAI 2026-10-01, GR-125-11). Nothing was charged; not
|
|
26
|
+
* retried. `candidates` lists them: [{entity_type, entity_id, name, country}] — call again with entityType + entityId from one.
|
|
27
|
+
* A ConflictError, so existing handlers still catch it. */
|
|
28
|
+
export class AmbiguousEntityError extends ConflictError {
|
|
29
|
+
constructor(statusCode, detail, requestId = null, candidates = []) {
|
|
30
|
+
super(statusCode, detail, requestId); this.jouleCost = 0; this.candidates = [...(candidates || [])];
|
|
31
|
+
}
|
|
32
|
+
}
|
|
24
33
|
export class RateLimitError extends GreenlandAIError {}
|
|
25
34
|
export class ServerError extends GreenlandAIError {}
|
|
26
35
|
export class NetworkError extends GreenlandAIError {
|
package/src/core/transport.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* 3 retries, 500ms initial, 8s max, x2 backoff, 100-300ms jitter; retryable =
|
|
5
5
|
* network/5xx/429; Retry-After honored. Layered rule: NOT_SUPPORTED tier => no auto-retry.
|
|
6
6
|
*/
|
|
7
|
-
import { ConflictError, NetworkError, ProofRefusedError, RateLimitError, ServerError, errorForStatus } from "./errors.js";
|
|
7
|
+
import { AmbiguousEntityError, ConflictError, NetworkError, ProofRefusedError, RateLimitError, ServerError, errorForStatus } from "./errors.js";
|
|
8
8
|
import { NOT_SUPPORTED, dispatch } from "./idempotency.js";
|
|
9
9
|
|
|
10
10
|
const DEFAULT_MAX_RETRIES = 3;
|
|
@@ -45,6 +45,20 @@ const PROOF_REFUSAL_PATHS = new Set([
|
|
|
45
45
|
"/api/v1/prove", "/api/v1/prove-batch", "/api/v1/compliance/attest", "/api/v1/archive", "/api/v1/proof/queue",
|
|
46
46
|
"/api/v1/disclose", "/api/v1/agreement/verify", "/api/v1/agreement/create",
|
|
47
47
|
]);
|
|
48
|
+
// GreenlandAI's graph routes answer a name that matches several entities with a 409 and NO charge (2026-10-01): the detail carries
|
|
49
|
+
// {error: "ambiguous_entity", candidates: [...]} — thrown as AmbiguousEntityError, never retried.
|
|
50
|
+
const ONE_ENTITY_PATHS = new Set([
|
|
51
|
+
"/api/v1/relationships", "/api/v1/relationships/graph", "/api/v1/relationships/path",
|
|
52
|
+
"/api/v1/relationships/subgraph", "/api/v1/relationships/cascade",
|
|
53
|
+
]);
|
|
54
|
+
/** The candidates of a GreenlandAI ambiguous-entity 409, else null. */
|
|
55
|
+
function ambiguousCandidates(err) {
|
|
56
|
+
let d = err.detail;
|
|
57
|
+
if (typeof d === "string") { try { d = JSON.parse(d); } catch { return null; } }
|
|
58
|
+
if (!d || typeof d !== "object" || d.error !== "ambiguous_entity") return null;
|
|
59
|
+
if ("candidates" in d) return d.candidates || [];
|
|
60
|
+
return (d.ambiguous || []).flatMap((a) => a.candidates || []); // /subgraph: per name
|
|
61
|
+
}
|
|
48
62
|
|
|
49
63
|
function isRetryable(err) {
|
|
50
64
|
// a 409 that carries a Retry-After is ENYAL's idempotency "request in progress" reply: retried with the same key after the
|
|
@@ -132,6 +146,14 @@ export class Transport {
|
|
|
132
146
|
refused.cause = err;
|
|
133
147
|
throw refused;
|
|
134
148
|
}
|
|
149
|
+
if (err.constructor === ConflictError && err.retryAfter == null && ONE_ENTITY_PATHS.has(pathTemplate)) {
|
|
150
|
+
const cands = ambiguousCandidates(err);
|
|
151
|
+
if (cands !== null) {
|
|
152
|
+
const amb = new AmbiguousEntityError(err.statusCode, err.detail, err.requestId, cands);
|
|
153
|
+
amb.cause = err;
|
|
154
|
+
throw amb;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
135
157
|
throw err;
|
|
136
158
|
}
|
|
137
159
|
let delay = Math.min(DEFAULT_INITIAL_DELAY * DEFAULT_BACKOFF_FACTOR ** attempt, DEFAULT_MAX_DELAY)
|
package/src/gldai.js
CHANGED
|
@@ -115,17 +115,20 @@ export class GldaiSubmodule {
|
|
|
115
115
|
if (entityType != null) params.entity_type = entityType;
|
|
116
116
|
return this._t.request(this._base, "GET", "/api/v1/nearby", { params, idempotencyKey });
|
|
117
117
|
}
|
|
118
|
-
/** GET /api/v1/relationships — labelled relationship hops (the MCP `hops` tool).
|
|
119
|
-
*
|
|
120
|
-
*
|
|
121
|
-
*
|
|
122
|
-
*
|
|
123
|
-
*
|
|
124
|
-
*
|
|
125
|
-
*
|
|
126
|
-
|
|
118
|
+
/** GET /api/v1/relationships — labelled relationship hops (the MCP `hops` tool). The answer is about ONE entity (GreenlandAI
|
|
119
|
+
* 2026-10-01): pin it with entityType ("company" | "infrastructure" | "deposit" | "project") + entityId, or pass `entity` — the
|
|
120
|
+
* one entity whose name equals it (case-insensitive), else the one whose name contains it. If several match, this throws
|
|
121
|
+
* AmbiguousEntityError (a 409, nothing charged) whose `.candidates` are [{entity_type, entity_id, name, country}] — call again
|
|
122
|
+
* with one. The response's `resolved` names the entity the answer is about. `hops` = depth 1-10. relationType (one relation
|
|
123
|
+
* label, e.g. OPERATES, CONTAINS, MEMBER_OF) is checked against the API's allow-list on BOTH paths (with or without entity): an
|
|
124
|
+
* unknown label is a 400 naming the allowed set, BEFORE any charge. Metered per hop against the CALLING agent's wallet (quote
|
|
125
|
+
* with billingQuote("/api/v1/relationships", n)): the response carries charged_joules (the settled all-in — 0 for an empty
|
|
126
|
+
* result) + the metering block (file header). */
|
|
127
|
+
relationships({ entity, hops = 1, relationType, search, limit = 50, offset = 0, entityType, entityId, idempotencyKey } = {}) {
|
|
127
128
|
const params = { hops, limit, offset };
|
|
128
129
|
if (entity) params.entity = entity;
|
|
130
|
+
if (entityType) params.entity_type = entityType;
|
|
131
|
+
if (entityId != null && entityId !== "") params.entity_id = entityId;
|
|
129
132
|
if (relationType) params.relation_type = relationType;
|
|
130
133
|
if (search) params.search = search;
|
|
131
134
|
return this._t.request(this._base, "GET", "/api/v1/relationships", { params, idempotencyKey });
|