@greenlandai/sdk 0.5.5 → 0.5.7

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,23 @@
1
+ ## 0.5.7 (2026-09-23)
2
+ - **Fix: an ENYAL OAuth access token is accepted as the OAuth credential.** ENYAL issues it as `eyl_` + a JWT;
3
+ `oauth_token` / `oauthToken` accepted only a bare JWT (`eyJ…`) and raised, pushing agents onto the API-key
4
+ parameter. It is now sent as `Authorization: Bearer eyl_…` (every door strips the prefix). Unchanged: an ENYAL
5
+ API key (`eyl_` + opaque, no dots) is still refused as an OAuth token, and anything passed as `api_key` still
6
+ goes out as X-API-Key exactly as before.
7
+ - `enyal.prove` / `prove_batch` / `disclose` docs describe `refunded_joules` (proofs paid for and not delivered
8
+ are refunded in the same call; `joule_cost` = the price minus it).
9
+ - Otherwise README-only (plus the JS `VERSION` export, which had stayed at "0.5.3" since 0.5.3).
10
+ - Hello-world no longer leads with `gldai.query()`: `/query` (natural language) and `/mapdata` (bulk map
11
+ layers) are closed to all callers. The example now prices a path with `billing_quote` and reads `companies`.
12
+ - New "The graph" section: what `client.gldai` reads (companies, resource deposits, infrastructure assets,
13
+ projects, commodities and their relationships), where the live totals are, and that query/mapdata are closed.
14
+ - Idempotency matrix lists the metered reads that work today (query/mapdata removed; relationships,
15
+ look_from, nearby, map_viewport, look_at added).
16
+ - Auth lines: an `eyl_` API key is an ENYAL key (`client.enyal`), not a cross-product key; `gai_` covers the
17
+ graph and the marketplace; an ENYAL OAuth token (`eyl_` + JWT) goes in as the OAuth credential.
18
+ - The ENYAL-only SDK is described as sitting alongside this one at 2.2.x (was "supersedes v2.1.x").
19
+ - JS README: code blocks marked `js` (were `python`); Python-only install extras removed; observability line in JS.
20
+
1
21
  ## 0.5.0 (2026-09-05)
2
22
  - **NEW contributor programme surface (TEN-13) on `client.gldai`.** Submit evidenced graph
3
23
  relationships to the GreenlandAI contributor door and manage the grant. Two credential modes:
package/README.md CHANGED
@@ -1,23 +1,21 @@
1
1
  # greenlandai (JavaScript)
2
2
 
3
3
  Unified SDK for the GreenlandAI ecosystem — ENYAL, JoulePAI, RAREEAI, GreenlandAI.
4
- **Supersedes but does not replace** `enyal-sdk` v2.1.x (permanent coexistence — the
5
- standalone enterprise track stays published and maintained; see design §5).
4
+ Sits alongside the ENYAL-only SDK (`enyal-sdk` on PyPI / `@enyalai/sdk` on npm, 2.2.x), which stays
5
+ published and maintained — use that one if you only need ENYAL.
6
6
 
7
7
  ## Install
8
8
  ```bash
9
- npm install @greenlandai/sdk # core
10
- pip install "greenlandai[bip39]" # + mnemonic recovery primitives
11
- pip install "greenlandai[otel]" # + OpenTelemetry metrics (opt-in; OFF by default)
9
+ npm install @greenlandai/sdk
12
10
  ```
13
11
 
14
12
  ## Auth
15
- ```python
13
+ ```js
16
14
  import { Client } from "@greenlandai/sdk"; // ESM
17
15
  const { Client } = require("@greenlandai/sdk"); // CJS
18
- const client = new Client({ apiKey: "eyl_..." }); // eyl_ (ENYAL / cross-product) API key
19
- const client = new Client({ apiKey: "gai_..." }); // gai_ (GreenlandAI agent key) — gldai intelligence
20
- const client = new Client({ oauthToken: jwt }); // web sessions: ENYAL-issued OAuth JWT
16
+ const client = new Client({ apiKey: "gai_..." }); // GreenlandAI agent key — the graph (client.gldai) + the marketplace (client.rareeai)
17
+ const client = new Client({ apiKey: "eyl_..." }); // ENYAL API key — ENYAL calls (client.enyal)
18
+ const client = new Client({ oauthToken: jwt }); // an OAuth JWT — bare, or ENYAL's OAuth token (eyl_ + JWT)
21
19
  // Any apiKey → X-API-Key; an oauthToken (JWT) → Authorization: Bearer. Pass exactly one.
22
20
  // Passing an API key via oauthToken (or a JWT via apiKey) throws immediately — no silent mis-route.
23
21
  // 401s surface to you (no auto-refresh); hook: onAuthExpired
@@ -30,14 +28,24 @@ const client = new Client({ oauthToken: jwt }); // web sessions: ENYAL-issu
30
28
  > `greenlandai.ai/api/v1/marketplace/*`.) `eyl_` / OAuth marketplace access is unaffected.
31
29
 
32
30
  ## Hello world (one per submodule)
33
- ```python
31
+ ```js
34
32
  await client.enyal.archive({ agentId: "agent-1", chunkType: "decision_record", chunkKey: "k1", data: { decision: "x" } });
35
33
  await client.joulepai.transfer("@bob", 1000, { note: "thanks" }); // auto idempotency key
36
34
  await client.rareeai.createRequest({ resourceType: "gpu" }); // marketplace (flat 1%, floor 50 J — parse fee_joules)
37
35
  await client.rareeai.oracleAssignments(); // oracle queue (0.3.6; the pool is invite-only at launch)
38
- await client.gldai.query("lithium deposits greenland");
36
+ await client.gldai.billingQuote("/api/v1/companies"); // free: the exact all-in price before you call
37
+ await client.gldai.companies({ search: "lithium" }); // the graph (metered; see charged_joules + metering)
39
38
  ```
40
39
 
40
+ ## The graph (client.gldai)
41
+ The physical economy as queryable data: companies, resource deposits, infrastructure assets, projects and
42
+ commodities, and the relationships between them (ownership, operation, supply). Structured reads —
43
+ companies, deposits, infrastructure, projects, relationships (hops), look_from, nearby, map_viewport,
44
+ look_at — are metered per call against the calling agent's own wallet; price any path first with
45
+ billing_quote (free). Live totals: `GET https://greenlandai.ai/api/v1/public/stats` (public).
46
+ `query` (natural language) and `mapdata` (bulk map layers) are **closed to all callers**; the methods
47
+ still resolve but the server refuses them before any charge — use the structured reads and map_viewport.
48
+
41
49
  ## Idempotency promise matrix (auto-retry behavior — design §6, post-G1 2026-06-10)
42
50
 
43
51
  | Method (py / js) | Wire class | Tier | Auto-retry |
@@ -53,13 +61,13 @@ await client.gldai.query("lithium deposits greenland");
53
61
  | joulepai.fund | — | NOT SUPPORTED | **OFF** (duplicate Stripe sessions possible) |
54
62
  | rareeai.create_provider/create_request/deliver/resolve | B | ENFORCED | ON |
55
63
  | rareeai.approve/reject/dispute/extend_dispute | — | NOT SUPPORTED | **OFF** |
56
- | gldai metered queries (companies/deposits/infrastructure/query/projects/mapdata) | C header X-Idempotency-Key | ENFORCED | ON |
64
+ | gldai metered reads (companies/deposits/infrastructure/projects/relationships/look_from/nearby/map_viewport/look_at) | C header X-Idempotency-Key | ENFORCED | ON |
57
65
  | all GET reads | — | safe | ON |
58
66
 
59
67
  Every billed call auto-generates a UUID4 key (stable across retries) unless you pass `idempotency_key` / `idempotencyKey` yourself.
60
68
 
61
69
  ## Observability (OFF by default)
62
- `Client(logger=my_logger, on_retry=..., on_terminal_failure=..., metrics=otel_metrics())` —
70
+ `new Client({ apiKey, logger: console, onRetry, onTerminalFailure, metrics })` —
63
71
  DEBUG logs redact Authorization + X-API-Key structurally.
64
72
 
65
73
  Migration from enyal-sdk 2.1.0: see MIGRATION.md. Changelog: CHANGELOG.md.
package/dist/index.cjs CHANGED
@@ -169,6 +169,7 @@ var DEFAULT_JITTER_MIN = 100;
169
169
  var DEFAULT_JITTER_MAX = 300;
170
170
  var sleep = (ms) => new Promise((r) => setTimeout(r, ms));
171
171
  var JWT_RE = /^eyJ[\w-]*\.[\w-]+\.[\w-]+$/;
172
+ var OAUTH_RE = /^(?:eyl_)?eyJ[\w-]*\.[\w-]+\.[\w-]+$/;
172
173
  function isRetryable(err) {
173
174
  return err instanceof NetworkError || err instanceof RateLimitError || err instanceof ServerError;
174
175
  }
@@ -195,7 +196,7 @@ var Transport = class {
195
196
  this._credential = apiKey;
196
197
  this._isApiKey = true;
197
198
  } else {
198
- if (!JWT_RE.test(oauthToken)) throw new Error("oauthToken is not a JWT \u2014 an API key (e.g. eyl_/gai_) must be passed via apiKey.");
199
+ if (!OAUTH_RE.test(oauthToken)) throw new Error("oauthToken is not a JWT (bare, or ENYAL's eyl_-prefixed OAuth token) \u2014 an API key (e.g. eyl_/gai_) must be passed via apiKey.");
199
200
  this._credential = oauthToken;
200
201
  this._isApiKey = false;
201
202
  }
@@ -3784,7 +3785,8 @@ var EnyalSubmodule = class {
3784
3785
  );
3785
3786
  }
3786
3787
  // ── class B (ENFORCED) ──
3787
- /** 2.1.0: enyal-client.js:472. ENFORCED (prove_routes.py:204). */
3788
+ /** 2.1.0: enyal-client.js:472. ENFORCED (prove_routes.py:204).
3789
+ * Filter queries: A proof paid for and not delivered is refunded in the same call: the response carries `refunded_joules` (refunds already sent back to your wallet) and `joule_cost` = the price minus it; a refund still in flight completes automatically and is not counted. A failure after the charge is an error and is refunded in full. */
3788
3790
  prove({
3789
3791
  resourceType,
3790
3792
  geographicRegion,
@@ -3801,6 +3803,8 @@ var EnyalSubmodule = class {
3801
3803
  if (chunkIds) body.chunk_ids = chunkIds;
3802
3804
  return this._t.request(this._base, "POST", "/api/v1/prove", { body, idempotencyKey, retry });
3803
3805
  }
3806
+ /** Each query without a proof (including one that matches nothing), and the compression fee when no compressed
3807
+ * proof comes back: A proof paid for and not delivered is refunded in the same call: the response carries `refunded_joules` (refunds already sent back to your wallet) and `joule_cost` = the price minus it; a refund still in flight completes automatically and is not counted. A failure after the charge is an error and is refunded in full. */
3804
3808
  proveBatch({ queries, quantumResistant = true, compress: compress2 = true, idempotencyKey, retry = true }) {
3805
3809
  return this._t.request(
3806
3810
  this._base,
@@ -3815,7 +3819,8 @@ var EnyalSubmodule = class {
3815
3819
  if (poseidonKeyHash) body.poseidon_key_hash = poseidonKeyHash;
3816
3820
  return this._t.request(this._base, "POST", "/api/v1/prove/share-combination", { body, idempotencyKey, retry });
3817
3821
  }
3818
- /** 2.1.0: enyal-client.js:483. ENFORCED (disclose_routes.py:274). */
3822
+ /** 2.1.0: enyal-client.js:483. ENFORCED (disclose_routes.py:274).
3823
+ * Content or share proofs: A proof paid for and not delivered is refunded in the same call: the response carries `refunded_joules` (refunds already sent back to your wallet) and `joule_cost` = the price minus it; a refund still in flight completes automatically and is not counted. A failure after the charge is an error and is refunded in full. */
3819
3824
  disclose({ chunkIds, recipientPubkeyHex, purpose, idempotencyKey, retry = true }) {
3820
3825
  return this._t.request(
3821
3826
  this._base,
@@ -4313,7 +4318,10 @@ var JoulepaiSubmodule = class {
4313
4318
  * top-level all_anchored (bool). status is the LEDGER state of the leg; txid is written at BROADCAST, not
4314
4319
  * confirmation — a leg can be settled with txid null (not broadcast yet, OR the anchor dead-lettered) or
4315
4320
  * carry a txid not yet on chain. anchor is the state to act on: queued | confirming | confirmed → poll
4316
- * (~30 s; txid may be null while queued); anchored → verify via the PUBLIC GET /transfer/{transfer_id}/proof;
4321
+ * (~30 s; txid may be null while queued); anchored → the leg's txid IS the chain proof: check it yourself
4322
+ * on any BSV block explorer (e.g. WhatsOnChain, whatsonchain.com/tx/<txid>) or with the MCP `verify_proof`
4323
+ * tool (txid in → chain_status / chain_confirmed). The legs carry NO transfer id, so
4324
+ * /transfer/{transfer_id}/proof is not reachable from this view;
4317
4325
  * failed | cancelled → the ledger leg settled but the anchor dead-lettered and will NOT reach the chain by
4318
4326
  * itself (escalate); none → no anchor attempted; unknown → a queue status the view does not recognise. A null
4319
4327
  * txid on a fresh read is NOT a missing or failed leg — read anchor. The trade-WIDE view — transferStatus()
@@ -4424,8 +4432,10 @@ var JoulepaiSubmodule = class {
4424
4432
  * never a parameter). Read-only, free. Returns { usdc_live, scanner_cursor_block, minimum_usdc,
4425
4433
  * deposits[], held_below_min_total_usdc, needed_to_credit_usdc, note }; each deposit carries { tx_hash,
4426
4434
  * block_number, usdc_amount, status, joules_credited, fee_taken, created_at, meaning }. A deposit whose
4427
- * block_number is ABOVE scanner_cursor_block has not been reached yet (normal lag), not lost. 503 when
4428
- * USDC-on-Base is not live. Parity with the MCP `deposit_status` tool. */
4435
+ * block_number is ABOVE scanner_cursor_block has not been reached yet (normal lag), not lost. status is one
4436
+ * of credited · held_below_min · held_above_max · swept · held_no_fund (the deposit reached the minimum but the platform's funding wallet could not cover the joules at that moment — held, nothing moved, nothing lost; credited AUTOMATICALLY once platform funding is restored — the scanner retries it every minute — no action needed from you).
4437
+ * Only credited has occurred on real funds so far. 503 when USDC-on-Base is not live. Parity with the MCP
4438
+ * `deposit_status` tool. */
4429
4439
  depositStatus() {
4430
4440
  return this._t.request(this._base, "GET", "/wallet/deposit-status", {});
4431
4441
  }
@@ -4754,7 +4764,7 @@ var RareeaiSubmodule = class _RareeaiSubmodule {
4754
4764
  };
4755
4765
 
4756
4766
  // index.js
4757
- var VERSION = "0.5.3";
4767
+ var VERSION = "0.5.7";
4758
4768
  var Client = class {
4759
4769
  /**
4760
4770
  * @param {object} opts
package/index.js CHANGED
@@ -16,7 +16,7 @@ export {
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.3";
19
+ export const VERSION = "0.5.7";
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.5",
3
+ "version": "0.5.7",
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",
@@ -20,6 +20,10 @@ const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
20
20
  // credential is passed via the wrong parameter. Prefixed API keys (eyl_/gai_/…) never match
21
21
  // this (a JWT starts "eyJ"); only a bare JWT does. Routing itself is by parameter, not prefix.
22
22
  const JWT_RE = /^eyJ[\w-]*\.[\w-]+\.[\w-]+$/;
23
+ // What oauthToken accepts: a bare JWT, or ENYAL's OAuth access token, which ENYAL issues as `eyl_` + an RS256 JWT
24
+ // (enyal oauth_routes.py) and which every door reads as Bearer after stripping the prefix. An ENYAL API key is also
25
+ // `eyl_`-prefixed but is opaque (no dots), so it can never match and is still refused here (0.5.7).
26
+ const OAUTH_RE = /^(?:eyl_)?eyJ[\w-]*\.[\w-]+\.[\w-]+$/;
23
27
 
24
28
  function isRetryable(err) {
25
29
  return err instanceof NetworkError || err instanceof RateLimitError || err instanceof ServerError;
@@ -39,7 +43,7 @@ export class Transport {
39
43
  if (JWT_RE.test(apiKey)) throw new Error("apiKey looks like a JWT (OAuth token) — pass it via oauthToken instead.");
40
44
  this._credential = apiKey; this._isApiKey = true;
41
45
  } else {
42
- if (!JWT_RE.test(oauthToken)) throw new Error("oauthToken is not a JWT — an API key (e.g. eyl_/gai_) must be passed via apiKey.");
46
+ if (!OAUTH_RE.test(oauthToken)) throw new Error("oauthToken is not a JWT (bare, or ENYAL's eyl_-prefixed OAuth token) — an API key (e.g. eyl_/gai_) must be passed via apiKey.");
43
47
  this._credential = oauthToken; this._isApiKey = false;
44
48
  }
45
49
  this.logger = logger || noopLogger;
package/src/enyal.js CHANGED
@@ -44,7 +44,8 @@ export class EnyalSubmodule {
44
44
  }
45
45
 
46
46
  // ── class B (ENFORCED) ──
47
- /** 2.1.0: enyal-client.js:472. ENFORCED (prove_routes.py:204). */
47
+ /** 2.1.0: enyal-client.js:472. ENFORCED (prove_routes.py:204).
48
+ * Filter queries: A proof paid for and not delivered is refunded in the same call: the response carries `refunded_joules` (refunds already sent back to your wallet) and `joule_cost` = the price minus it; a refund still in flight completes automatically and is not counted. A failure after the charge is an error and is refunded in full. */
48
49
  prove({ resourceType, geographicRegion, supplyChainStage, chunkIds, quantumResistant = false,
49
50
  idempotencyKey, retry = true } = {}) {
50
51
  const body = { quantum_resistant: quantumResistant };
@@ -55,6 +56,8 @@ export class EnyalSubmodule {
55
56
  return this._t.request(this._base, "POST", "/api/v1/prove", { body, idempotencyKey, retry });
56
57
  }
57
58
 
59
+ /** Each query without a proof (including one that matches nothing), and the compression fee when no compressed
60
+ * proof comes back: A proof paid for and not delivered is refunded in the same call: the response carries `refunded_joules` (refunds already sent back to your wallet) and `joule_cost` = the price minus it; a refund still in flight completes automatically and is not counted. A failure after the charge is an error and is refunded in full. */
58
61
  proveBatch({ queries, quantumResistant = true, compress = true, idempotencyKey, retry = true }) {
59
62
  return this._t.request(this._base, "POST", "/api/v1/prove-batch",
60
63
  { body: { queries, quantum_resistant: quantumResistant, compress }, idempotencyKey, retry });
@@ -67,7 +70,8 @@ export class EnyalSubmodule {
67
70
  return this._t.request(this._base, "POST", "/api/v1/prove/share-combination", { body, idempotencyKey, retry });
68
71
  }
69
72
 
70
- /** 2.1.0: enyal-client.js:483. ENFORCED (disclose_routes.py:274). */
73
+ /** 2.1.0: enyal-client.js:483. ENFORCED (disclose_routes.py:274).
74
+ * Content or share proofs: A proof paid for and not delivered is refunded in the same call: the response carries `refunded_joules` (refunds already sent back to your wallet) and `joule_cost` = the price minus it; a refund still in flight completes automatically and is not counted. A failure after the charge is an error and is refunded in full. */
71
75
  disclose({ chunkIds, recipientPubkeyHex, purpose, idempotencyKey, retry = true }) {
72
76
  return this._t.request(this._base, "POST", "/api/v1/disclose",
73
77
  { body: { chunk_ids: chunkIds, recipient_pubkey_hex: recipientPubkeyHex, purpose }, idempotencyKey, retry });
package/src/joulepai.js CHANGED
@@ -61,7 +61,10 @@ export class JoulepaiSubmodule {
61
61
  * top-level all_anchored (bool). status is the LEDGER state of the leg; txid is written at BROADCAST, not
62
62
  * confirmation — a leg can be settled with txid null (not broadcast yet, OR the anchor dead-lettered) or
63
63
  * carry a txid not yet on chain. anchor is the state to act on: queued | confirming | confirmed → poll
64
- * (~30 s; txid may be null while queued); anchored → verify via the PUBLIC GET /transfer/{transfer_id}/proof;
64
+ * (~30 s; txid may be null while queued); anchored → the leg's txid IS the chain proof: check it yourself
65
+ * on any BSV block explorer (e.g. WhatsOnChain, whatsonchain.com/tx/<txid>) or with the MCP `verify_proof`
66
+ * tool (txid in → chain_status / chain_confirmed). The legs carry NO transfer id, so
67
+ * /transfer/{transfer_id}/proof is not reachable from this view;
65
68
  * failed | cancelled → the ledger leg settled but the anchor dead-lettered and will NOT reach the chain by
66
69
  * itself (escalate); none → no anchor attempted; unknown → a queue status the view does not recognise. A null
67
70
  * txid on a fresh read is NOT a missing or failed leg — read anchor. The trade-WIDE view — transferStatus()
@@ -152,8 +155,10 @@ export class JoulepaiSubmodule {
152
155
  * never a parameter). Read-only, free. Returns { usdc_live, scanner_cursor_block, minimum_usdc,
153
156
  * deposits[], held_below_min_total_usdc, needed_to_credit_usdc, note }; each deposit carries { tx_hash,
154
157
  * block_number, usdc_amount, status, joules_credited, fee_taken, created_at, meaning }. A deposit whose
155
- * block_number is ABOVE scanner_cursor_block has not been reached yet (normal lag), not lost. 503 when
156
- * USDC-on-Base is not live. Parity with the MCP `deposit_status` tool. */
158
+ * block_number is ABOVE scanner_cursor_block has not been reached yet (normal lag), not lost. status is one
159
+ * of credited · held_below_min · held_above_max · swept · held_no_fund (the deposit reached the minimum but the platform's funding wallet could not cover the joules at that moment — held, nothing moved, nothing lost; credited AUTOMATICALLY once platform funding is restored — the scanner retries it every minute — no action needed from you).
160
+ * Only credited has occurred on real funds so far. 503 when USDC-on-Base is not live. Parity with the MCP
161
+ * `deposit_status` tool. */
157
162
  depositStatus() { return this._t.request(this._base, "GET", "/wallet/deposit-status", {}); }
158
163
 
159
164
  /** The in-band funding step for a joule shortfall — NEVER a URL to visit (operator lock). USDC on Base is