@greenlandai/sdk 0.5.13 → 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 CHANGED
@@ -1,3 +1,16 @@
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
+
9
+ ## 0.5.14 (2026-09-30)
10
+ - **`client.enyal.createAgreement()` on a zero-knowledge account** — ENYAL (6961c0e) refuses it with an uncharged 409; it now
11
+ throws `ProofRefusedError` (`.jouleCost 0`, not retried) like the other uncharged refusals, instead of a plain `ConflictError`.
12
+ - The restore fix of this release is in the Python `EnyalAgent`; JavaScript users have it in @enyalai/sdk 2.2.12.
13
+
1
14
  ## 0.5.13 (2026-09-30)
2
15
  - **Zero-knowledge record envelope (ENYAL #6; RUL-0054/RUL-0055)** — the same change as @enyalai/sdk 2.2.11:
3
16
  `crypto.decryptDisclosedChunk()` opens the `"ENYC" ‖ 0x01 ‖ r ‖ content` envelope of a record marked `hash_scheme:
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 {
@@ -189,8 +197,29 @@ var PROOF_REFUSAL_PATHS = /* @__PURE__ */ new Set([
189
197
  "/api/v1/archive",
190
198
  "/api/v1/proof/queue",
191
199
  "/api/v1/disclose",
192
- "/api/v1/agreement/verify"
200
+ "/api/v1/agreement/verify",
201
+ "/api/v1/agreement/create"
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"
193
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
+ }
194
223
  function isRetryable(err) {
195
224
  if (err instanceof ConflictError && err.retryAfter != null) return true;
196
225
  return err instanceof NetworkError || err instanceof RateLimitError || err instanceof ServerError;
@@ -283,6 +312,14 @@ var Transport = class {
283
312
  refused.cause = err;
284
313
  throw refused;
285
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
+ }
286
323
  throw err;
287
324
  }
288
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);
@@ -4227,17 +4264,20 @@ var GldaiSubmodule = class {
4227
4264
  if (entityType != null) params.entity_type = entityType;
4228
4265
  return this._t.request(this._base, "GET", "/api/v1/nearby", { params, idempotencyKey });
4229
4266
  }
4230
- /** GET /api/v1/relationships — labelled relationship hops (the MCP `hops` tool). `entity` is the START
4231
- * NODE, matched as a case-insensitive SUBSTRING of an entity NAME (never an id: "3" matches any name
4232
- * containing "3"), so pass a full, distinctive name. `hops` = depth 1-10. relationType (one relation label,
4233
- * e.g. OPERATES, CONTAINS, MEMBER_OF) is checked against the API's allow-list on BOTH paths (with or without
4234
- * entity, backend a3c97f9): an unknown label is a 400 naming the allowed set, BEFORE any charge — never an
4235
- * empty 200. Metered per hop against the CALLING agent's wallet (quote with
4236
- * billingQuote("/api/v1/relationships", n)): the response carries charged_joules (the settled all-in — 0 for
4237
- * an empty result) + the metering block (file header). */
4238
- relationships({ entity, hops = 1, relationType, search, limit = 50, offset = 0, idempotencyKey } = {}) {
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 } = {}) {
4239
4277
  const params = { hops, limit, offset };
4240
4278
  if (entity) params.entity = entity;
4279
+ if (entityType) params.entity_type = entityType;
4280
+ if (entityId != null && entityId !== "") params.entity_id = entityId;
4241
4281
  if (relationType) params.relation_type = relationType;
4242
4282
  if (search) params.search = search;
4243
4283
  return this._t.request(this._base, "GET", "/api/v1/relationships", { params, idempotencyKey });
@@ -4888,7 +4928,7 @@ var RareeaiSubmodule = class _RareeaiSubmodule {
4888
4928
  };
4889
4929
 
4890
4930
  // index.js
4891
- var VERSION = "0.5.13";
4931
+ var VERSION = "0.5.15";
4892
4932
  var Client = class {
4893
4933
  /**
4894
4934
  * @param {object} opts
@@ -4930,6 +4970,7 @@ var Client = class {
4930
4970
  };
4931
4971
  // Annotate the CommonJS export names for ESM import in node:
4932
4972
  0 && (module.exports = {
4973
+ AmbiguousEntityError,
4933
4974
  AuthError,
4934
4975
  Client,
4935
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.13";
19
+ export const VERSION = "0.5.15";
20
20
 
21
21
  export class Client {
22
22
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@greenlandai/sdk",
3
- "version": "0.5.13",
3
+ "version": "0.5.15",
4
4
  "description": "Unified SDK for the GreenlandAI ecosystem (ENYAL, JoulePAI, RAREEAI, GreenlandAI)",
5
5
  "license": "Apache-2.0",
6
6
  "homepage": "https://greenlandai.ai",
@@ -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 {
@@ -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;
@@ -39,12 +39,26 @@ function parseRetryAfter(value) {
39
39
 
40
40
  // Paths where ENYAL answers a request it will not serve with a 409 and NO charge (2026-09-30): a proof over zero-knowledge
41
41
  // records (/prove, /prove-batch, /compliance/attest, /archive with proof_tier, /proof/queue), a SHA-256 content proof on
42
- // /disclose, and /agreement/verify on a zero-knowledge record. ENYAL's idempotency "in progress" 409 on the same paths carries a
42
+ // /disclose, /agreement/verify on a zero-knowledge record, and /agreement/create on a zero-knowledge account (ENYAL 6961c0e). ENYAL's idempotency "in progress" 409 on the same paths carries a
43
43
  // Retry-After and is retried instead (it is never a ProofRefusedError).
44
44
  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
- "/api/v1/disclose", "/api/v1/agreement/verify",
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). `entity` is the START
119
- * NODE, matched as a case-insensitive SUBSTRING of an entity NAME (never an id: "3" matches any name
120
- * containing "3"), so pass a full, distinctive name. `hops` = depth 1-10. relationType (one relation label,
121
- * e.g. OPERATES, CONTAINS, MEMBER_OF) is checked against the API's allow-list on BOTH paths (with or without
122
- * entity, backend a3c97f9): an unknown label is a 400 naming the allowed set, BEFORE any charge — never an
123
- * empty 200. Metered per hop against the CALLING agent's wallet (quote with
124
- * billingQuote("/api/v1/relationships", n)): the response carries charged_joules (the settled all-in — 0 for
125
- * an empty result) + the metering block (file header). */
126
- relationships({ entity, hops = 1, relationType, search, limit = 50, offset = 0, idempotencyKey } = {}) {
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 });