@greenlandai/sdk 0.5.14 → 0.5.16
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 +17 -0
- package/dist/index.cjs +60 -11
- package/index.js +2 -2
- package/package.json +1 -1
- package/src/core/errors.js +9 -0
- package/src/core/transport.js +39 -2
- package/src/gldai.js +12 -9
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,20 @@
|
|
|
1
|
+
## 0.5.16 (2026-10-03)
|
|
2
|
+
- **A missing path id is refused before any request** (all 29 methods that put an id in the URL path: ENYAL lineage / thread /
|
|
3
|
+
knowledge nodes, GreenlandAI company / deposit / infrastructure / project, RAREEAI match actions, JoulePAI wallet / transfer /
|
|
4
|
+
funding). None / undefined, a non-string (an integer is allowed), an empty or blank string, or the text a missing value turns
|
|
5
|
+
into ("undefined", "null", "None", "NaN") raise `ValueError` (Python) / `TypeError` (JS). Until now the request went out with
|
|
6
|
+
"None" / "undefined" in the path.
|
|
7
|
+
- **Path ids are percent-encoded as one segment in Python too** (JS already encoded them). Until now the Python client sent an id
|
|
8
|
+
raw, so an id containing "/", "?" or "#" reached a different route.
|
|
9
|
+
|
|
10
|
+
## 0.5.15 (2026-10-01)
|
|
11
|
+
- **GreenlandAI's graph answers are about ONE entity** (GreenlandAI 8c0ec77). `client.gldai.relationships()` takes `entityType`
|
|
12
|
+
("company" | "infrastructure" | "deposit" | "project") + `entityId` to pin the start node; `entity` resolves to the one entity
|
|
13
|
+
whose name equals it, else the one whose name contains it. Until 2026-10-01 the server merged every entity whose name contained
|
|
14
|
+
the term into one answer (two plants sharing a name came back as one); it now refuses: several matches throw the new
|
|
15
|
+
`AmbiguousEntityError` (a `ConflictError`; HTTP 409, `.jouleCost` 0, not retried) whose `.candidates` are
|
|
16
|
+
`[{entity_type, entity_id, name, country}]` — call again with one. Every answer carries `resolved`.
|
|
17
|
+
|
|
1
18
|
## 0.5.14 (2026-09-30)
|
|
2
19
|
- **`client.enyal.createAgreement()` on a zero-knowledge account** — ENYAL (6961c0e) refuses it with an uncharged 409; it now
|
|
3
20
|
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;
|
|
@@ -201,6 +229,15 @@ var noopLogger = { debug() {
|
|
|
201
229
|
}, warn() {
|
|
202
230
|
}, error() {
|
|
203
231
|
} };
|
|
232
|
+
var _MISSING_ID_TEXT = /* @__PURE__ */ new Set(["", "undefined", "null", "none", "nan"]);
|
|
233
|
+
function _pathId(name, value) {
|
|
234
|
+
const ok = typeof value === "string" || typeof value === "number" && Number.isFinite(value);
|
|
235
|
+
if (!ok) {
|
|
236
|
+
throw new TypeError(`${name} must be a non-empty string id (got ${value === null ? "null" : Array.isArray(value) ? "array" : typeof value}); no request was sent`);
|
|
237
|
+
}
|
|
238
|
+
if (_MISSING_ID_TEXT.has(String(value).trim().toLowerCase())) throw new TypeError(`${name} is empty or missing; no request was sent`);
|
|
239
|
+
return encodeURIComponent(String(value));
|
|
240
|
+
}
|
|
204
241
|
var Transport = class {
|
|
205
242
|
constructor({
|
|
206
243
|
apiKey,
|
|
@@ -253,7 +290,7 @@ var Transport = class {
|
|
|
253
290
|
headers = d.headers;
|
|
254
291
|
if (d.tier === NOT_SUPPORTED) retry = false;
|
|
255
292
|
let path = pathTemplate;
|
|
256
|
-
for (const [k, v] of Object.entries(pathParams)) path = path.replace(`{${k}}`,
|
|
293
|
+
for (const [k, v] of Object.entries(pathParams)) path = path.replace(`{${k}}`, _pathId(k, v));
|
|
257
294
|
let url = `${baseUrl.replace(/\/+$/, "")}${path}`;
|
|
258
295
|
if (params) {
|
|
259
296
|
const qs = new URLSearchParams(
|
|
@@ -284,6 +321,14 @@ var Transport = class {
|
|
|
284
321
|
refused.cause = err;
|
|
285
322
|
throw refused;
|
|
286
323
|
}
|
|
324
|
+
if (err.constructor === ConflictError && err.retryAfter == null && ONE_ENTITY_PATHS.has(pathTemplate)) {
|
|
325
|
+
const cands = ambiguousCandidates(err);
|
|
326
|
+
if (cands !== null) {
|
|
327
|
+
const amb = new AmbiguousEntityError(err.statusCode, err.detail, err.requestId, cands);
|
|
328
|
+
amb.cause = err;
|
|
329
|
+
throw amb;
|
|
330
|
+
}
|
|
331
|
+
}
|
|
287
332
|
throw err;
|
|
288
333
|
}
|
|
289
334
|
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 +4273,20 @@ var GldaiSubmodule = class {
|
|
|
4228
4273
|
if (entityType != null) params.entity_type = entityType;
|
|
4229
4274
|
return this._t.request(this._base, "GET", "/api/v1/nearby", { params, idempotencyKey });
|
|
4230
4275
|
}
|
|
4231
|
-
/** GET /api/v1/relationships — labelled relationship hops (the MCP `hops` tool).
|
|
4232
|
-
*
|
|
4233
|
-
*
|
|
4234
|
-
*
|
|
4235
|
-
*
|
|
4236
|
-
*
|
|
4237
|
-
*
|
|
4238
|
-
*
|
|
4239
|
-
|
|
4276
|
+
/** GET /api/v1/relationships — labelled relationship hops (the MCP `hops` tool). The answer is about ONE entity (GreenlandAI
|
|
4277
|
+
* 2026-10-01): pin it with entityType ("company" | "infrastructure" | "deposit" | "project") + entityId, or pass `entity` — the
|
|
4278
|
+
* one entity whose name equals it (case-insensitive), else the one whose name contains it. If several match, this throws
|
|
4279
|
+
* AmbiguousEntityError (a 409, nothing charged) whose `.candidates` are [{entity_type, entity_id, name, country}] — call again
|
|
4280
|
+
* with one. The response's `resolved` names the entity the answer is about. `hops` = depth 1-10. relationType (one relation
|
|
4281
|
+
* label, e.g. OPERATES, CONTAINS, MEMBER_OF) is checked against the API's allow-list on BOTH paths (with or without entity): an
|
|
4282
|
+
* unknown label is a 400 naming the allowed set, BEFORE any charge. Metered per hop against the CALLING agent's wallet (quote
|
|
4283
|
+
* with billingQuote("/api/v1/relationships", n)): the response carries charged_joules (the settled all-in — 0 for an empty
|
|
4284
|
+
* result) + the metering block (file header). */
|
|
4285
|
+
relationships({ entity, hops = 1, relationType, search, limit = 50, offset = 0, entityType, entityId, idempotencyKey } = {}) {
|
|
4240
4286
|
const params = { hops, limit, offset };
|
|
4241
4287
|
if (entity) params.entity = entity;
|
|
4288
|
+
if (entityType) params.entity_type = entityType;
|
|
4289
|
+
if (entityId != null && entityId !== "") params.entity_id = entityId;
|
|
4242
4290
|
if (relationType) params.relation_type = relationType;
|
|
4243
4291
|
if (search) params.search = search;
|
|
4244
4292
|
return this._t.request(this._base, "GET", "/api/v1/relationships", { params, idempotencyKey });
|
|
@@ -4889,7 +4937,7 @@ var RareeaiSubmodule = class _RareeaiSubmodule {
|
|
|
4889
4937
|
};
|
|
4890
4938
|
|
|
4891
4939
|
// index.js
|
|
4892
|
-
var VERSION = "0.5.
|
|
4940
|
+
var VERSION = "0.5.16";
|
|
4893
4941
|
var Client = class {
|
|
4894
4942
|
/**
|
|
4895
4943
|
* @param {object} opts
|
|
@@ -4931,6 +4979,7 @@ var Client = class {
|
|
|
4931
4979
|
};
|
|
4932
4980
|
// Annotate the CommonJS export names for ESM import in node:
|
|
4933
4981
|
0 && (module.exports = {
|
|
4982
|
+
AmbiguousEntityError,
|
|
4934
4983
|
AuthError,
|
|
4935
4984
|
Client,
|
|
4936
4985
|
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.16";
|
|
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
|
|
@@ -55,6 +69,21 @@ function isRetryable(err) {
|
|
|
55
69
|
|
|
56
70
|
const noopLogger = { debug() {}, info() {}, warn() {}, error() {} };
|
|
57
71
|
|
|
72
|
+
// A record id in a URL path (P-DAY.126, operator: "/lineage/undefined is our client letting a bad call through"). Every path id goes
|
|
73
|
+
// through here (29 call sites): a missing id is refused BEFORE any request — undefined, null, a non-string (a finite number is allowed),
|
|
74
|
+
// an empty or blank string, or the text a missing value turns into ('undefined', 'null', 'None', 'NaN'); a real id is sent as ONE
|
|
75
|
+
// percent-encoded path segment. The error names the parameter and the type only — never the value.
|
|
76
|
+
const _MISSING_ID_TEXT = new Set(["", "undefined", "null", "none", "nan"]);
|
|
77
|
+
|
|
78
|
+
function _pathId(name, value) {
|
|
79
|
+
const ok = typeof value === "string" || (typeof value === "number" && Number.isFinite(value));
|
|
80
|
+
if (!ok) {
|
|
81
|
+
throw new TypeError(`${name} must be a non-empty string id (got ${value === null ? "null" : Array.isArray(value) ? "array" : typeof value}); no request was sent`);
|
|
82
|
+
}
|
|
83
|
+
if (_MISSING_ID_TEXT.has(String(value).trim().toLowerCase())) throw new TypeError(`${name} is empty or missing; no request was sent`);
|
|
84
|
+
return encodeURIComponent(String(value));
|
|
85
|
+
}
|
|
86
|
+
|
|
58
87
|
export class Transport {
|
|
59
88
|
constructor({ apiKey, oauthToken, logger, onRetry, onTerminalFailure,
|
|
60
89
|
onAuthExpired, metrics, fetchImpl } = {}) {
|
|
@@ -101,7 +130,7 @@ export class Transport {
|
|
|
101
130
|
if (d.tier === NOT_SUPPORTED) retry = false; // §3.1 layered rule
|
|
102
131
|
|
|
103
132
|
let path = pathTemplate;
|
|
104
|
-
for (const [k, v] of Object.entries(pathParams)) path = path.replace(`{${k}}`,
|
|
133
|
+
for (const [k, v] of Object.entries(pathParams)) path = path.replace(`{${k}}`, _pathId(k, v));
|
|
105
134
|
let url = `${baseUrl.replace(/\/+$/, "")}${path}`;
|
|
106
135
|
if (params) {
|
|
107
136
|
const qs = new URLSearchParams(
|
|
@@ -132,6 +161,14 @@ export class Transport {
|
|
|
132
161
|
refused.cause = err;
|
|
133
162
|
throw refused;
|
|
134
163
|
}
|
|
164
|
+
if (err.constructor === ConflictError && err.retryAfter == null && ONE_ENTITY_PATHS.has(pathTemplate)) {
|
|
165
|
+
const cands = ambiguousCandidates(err);
|
|
166
|
+
if (cands !== null) {
|
|
167
|
+
const amb = new AmbiguousEntityError(err.statusCode, err.detail, err.requestId, cands);
|
|
168
|
+
amb.cause = err;
|
|
169
|
+
throw amb;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
135
172
|
throw err;
|
|
136
173
|
}
|
|
137
174
|
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 });
|