@greenlandai/sdk 0.5.6 → 0.5.8

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,39 @@
1
+ ## 0.5.8 (2026-09-28)
2
+ - **Fix: `EnyalAgent` (Python) no longer archives under the fixed ids `sdk-agent` / `sdk-sync`.** ENYAL now refuses an
3
+ agent id another account already holds (403), so a fixed id shared by every customer belonged to the first account
4
+ to use it. The default is the account's OWN JoulePAI wallet id (looked up once via `GET /api/v1/account`); an
5
+ account with no wallet must pass an agent_id of its own. `inbox()` with no agent_id reads the own wallet id.
6
+ - **Fix: `Retry-After` was honoured with no upper limit** — ENYAL's `Retry-After: 3600` slept an hour per retry. Now
7
+ honoured up to 60 seconds; longer is not slept through — the error is raised with `retry_after` set (both languages).
8
+ - **Fix: a `Retry-After` that is not a number of seconds no longer breaks the call.** The header may be an HTTP-date
9
+ (RFC 9110); Python raised `ValueError` on any response carrying one (even a 200), and JS set `retryAfter` to
10
+ `NaN`. Anything that is not a finite, non-negative number of seconds now counts as absent: ordinary backoff, and
11
+ `retry_after` / `retryAfter` is `None` / `null` (both languages).
12
+ - Added `client.enyal.get_account()` / `getAccount()` — `GET /api/v1/account` (id, tier, `wallet_id`, …).
13
+ - Docs: messages are addressed by the recipient's JoulePAI wallet id (agent names and free-form ids are private labels
14
+ and get 409); read your inbox with your own wallet id. README examples use a placeholder agent id and say it must be
15
+ your own.
16
+
17
+ ## 0.5.7 (2026-09-23)
18
+ - **Fix: an ENYAL OAuth access token is accepted as the OAuth credential.** ENYAL issues it as `eyl_` + a JWT;
19
+ `oauth_token` / `oauthToken` accepted only a bare JWT (`eyJ…`) and raised, pushing agents onto the API-key
20
+ parameter. It is now sent as `Authorization: Bearer eyl_…` (every door strips the prefix). Unchanged: an ENYAL
21
+ API key (`eyl_` + opaque, no dots) is still refused as an OAuth token, and anything passed as `api_key` still
22
+ goes out as X-API-Key exactly as before.
23
+ - `enyal.prove` / `prove_batch` / `disclose` docs describe `refunded_joules` (proofs paid for and not delivered
24
+ are refunded in the same call; `joule_cost` = the price minus it).
25
+ - Otherwise README-only (plus the JS `VERSION` export, which had stayed at "0.5.3" since 0.5.3).
26
+ - Hello-world no longer leads with `gldai.query()`: `/query` (natural language) and `/mapdata` (bulk map
27
+ layers) are closed to all callers. The example now prices a path with `billing_quote` and reads `companies`.
28
+ - New "The graph" section: what `client.gldai` reads (companies, resource deposits, infrastructure assets,
29
+ projects, commodities and their relationships), where the live totals are, and that query/mapdata are closed.
30
+ - Idempotency matrix lists the metered reads that work today (query/mapdata removed; relationships,
31
+ look_from, nearby, map_viewport, look_at added).
32
+ - Auth lines: an `eyl_` API key is an ENYAL key (`client.enyal`), not a cross-product key; `gai_` covers the
33
+ graph and the marketplace; an ENYAL OAuth token (`eyl_` + JWT) goes in as the OAuth credential.
34
+ - The ENYAL-only SDK is described as sitting alongside this one at 2.2.x (was "supersedes v2.1.x").
35
+ - JS README: code blocks marked `js` (were `python`); Python-only install extras removed; observability line in JS.
36
+
1
37
  ## 0.5.0 (2026-09-05)
2
38
  - **NEW contributor programme surface (TEN-13) on `client.gldai`.** Submit evidenced graph
3
39
  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,27 @@ 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
34
- await client.enyal.archive({ agentId: "agent-1", chunkType: "decision_record", chunkKey: "k1", data: { decision: "x" } });
31
+ ```js
32
+ // agentId must be your own: an id another account has used is refused (403), and web-console / web-app /
33
+ // share-extension are reserved for the account owner's apps. Your wallet id (client.enyal.getAccount()).wallet_id
34
+ // is always yours. Messages are addressed by the recipient's JoulePAI wallet id.
35
+ await client.enyal.archive({ agentId: "<your-own-agent-id>", chunkType: "decision_record", chunkKey: "k1", data: { decision: "x" } });
35
36
  await client.joulepai.transfer("@bob", 1000, { note: "thanks" }); // auto idempotency key
36
37
  await client.rareeai.createRequest({ resourceType: "gpu" }); // marketplace (flat 1%, floor 50 J — parse fee_joules)
37
38
  await client.rareeai.oracleAssignments(); // oracle queue (0.3.6; the pool is invite-only at launch)
38
- await client.gldai.query("lithium deposits greenland");
39
+ await client.gldai.billingQuote("/api/v1/companies"); // free: the exact all-in price before you call
40
+ await client.gldai.companies({ search: "lithium" }); // the graph (metered; see charged_joules + metering)
39
41
  ```
40
42
 
43
+ ## The graph (client.gldai)
44
+ The physical economy as queryable data: companies, resource deposits, infrastructure assets, projects and
45
+ commodities, and the relationships between them (ownership, operation, supply). Structured reads —
46
+ companies, deposits, infrastructure, projects, relationships (hops), look_from, nearby, map_viewport,
47
+ look_at — are metered per call against the calling agent's own wallet; price any path first with
48
+ billing_quote (free). Live totals: `GET https://greenlandai.ai/api/v1/public/stats` (public).
49
+ `query` (natural language) and `mapdata` (bulk map layers) are **closed to all callers**; the methods
50
+ still resolve but the server refuses them before any charge — use the structured reads and map_viewport.
51
+
41
52
  ## Idempotency promise matrix (auto-retry behavior — design §6, post-G1 2026-06-10)
42
53
 
43
54
  | Method (py / js) | Wire class | Tier | Auto-retry |
@@ -53,13 +64,13 @@ await client.gldai.query("lithium deposits greenland");
53
64
  | joulepai.fund | — | NOT SUPPORTED | **OFF** (duplicate Stripe sessions possible) |
54
65
  | rareeai.create_provider/create_request/deliver/resolve | B | ENFORCED | ON |
55
66
  | 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 |
67
+ | gldai metered reads (companies/deposits/infrastructure/projects/relationships/look_from/nearby/map_viewport/look_at) | C header X-Idempotency-Key | ENFORCED | ON |
57
68
  | all GET reads | — | safe | ON |
58
69
 
59
70
  Every billed call auto-generates a UUID4 key (stable across retries) unless you pass `idempotency_key` / `idempotencyKey` yourself.
60
71
 
61
72
  ## Observability (OFF by default)
62
- `Client(logger=my_logger, on_retry=..., on_terminal_failure=..., metrics=otel_metrics())` —
73
+ `new Client({ apiKey, logger: console, onRetry, onTerminalFailure, metrics })` —
63
74
  DEBUG logs redact Authorization + X-API-Key structurally.
64
75
 
65
76
  Migration from enyal-sdk 2.1.0: see MIGRATION.md. Changelog: CHANGELOG.md.
package/dist/index.cjs CHANGED
@@ -167,8 +167,15 @@ var DEFAULT_MAX_DELAY = 8e3;
167
167
  var DEFAULT_BACKOFF_FACTOR = 2;
168
168
  var DEFAULT_JITTER_MIN = 100;
169
169
  var DEFAULT_JITTER_MAX = 300;
170
+ var MAX_RETRY_AFTER_SECONDS = 60;
170
171
  var sleep = (ms) => new Promise((r) => setTimeout(r, ms));
171
172
  var JWT_RE = /^eyJ[\w-]*\.[\w-]+\.[\w-]+$/;
173
+ var OAUTH_RE = /^(?:eyl_)?eyJ[\w-]*\.[\w-]+\.[\w-]+$/;
174
+ function parseRetryAfter(value) {
175
+ if (value == null || value === "") return null;
176
+ const seconds = Number(value);
177
+ return Number.isFinite(seconds) && seconds >= 0 ? seconds : null;
178
+ }
172
179
  function isRetryable(err) {
173
180
  return err instanceof NetworkError || err instanceof RateLimitError || err instanceof ServerError;
174
181
  }
@@ -195,7 +202,7 @@ var Transport = class {
195
202
  this._credential = apiKey;
196
203
  this._isApiKey = true;
197
204
  } 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.");
205
+ 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
206
  this._credential = oauthToken;
200
207
  this._isApiKey = false;
201
208
  }
@@ -251,7 +258,8 @@ var Transport = class {
251
258
  return result;
252
259
  } catch (err) {
253
260
  if (err.statusCode === 401 && this.onAuthExpired) this.onAuthExpired(err);
254
- if (!retry || attempt >= maxRetries || !isRetryable(err)) {
261
+ const raTooLong = err.retryAfter != null && Number(err.retryAfter) > MAX_RETRY_AFTER_SECONDS;
262
+ if (!retry || attempt >= maxRetries || !isRetryable(err) || raTooLong) {
255
263
  if (this.onTerminalFailure) this.onTerminalFailure(err, attempt + 1);
256
264
  this.logger.warn(`terminal failure ${method} ${path} after ${attempt + 1} attempt(s)`);
257
265
  throw err;
@@ -285,7 +293,7 @@ var Transport = class {
285
293
  }
286
294
  const requestId = resp.headers?.get ? resp.headers.get("x-request-id") : null;
287
295
  const ra = resp.headers?.get ? resp.headers.get("retry-after") : null;
288
- const retryAfter = ra ? Number(ra) : null;
296
+ const retryAfter = parseRetryAfter(ra);
289
297
  if (resp.status >= 400) {
290
298
  let detail;
291
299
  try {
@@ -3784,7 +3792,8 @@ var EnyalSubmodule = class {
3784
3792
  );
3785
3793
  }
3786
3794
  // ── class B (ENFORCED) ──
3787
- /** 2.1.0: enyal-client.js:472. ENFORCED (prove_routes.py:204). */
3795
+ /** 2.1.0: enyal-client.js:472. ENFORCED (prove_routes.py:204).
3796
+ * 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
3797
  prove({
3789
3798
  resourceType,
3790
3799
  geographicRegion,
@@ -3801,6 +3810,8 @@ var EnyalSubmodule = class {
3801
3810
  if (chunkIds) body.chunk_ids = chunkIds;
3802
3811
  return this._t.request(this._base, "POST", "/api/v1/prove", { body, idempotencyKey, retry });
3803
3812
  }
3813
+ /** Each query without a proof (including one that matches nothing), and the compression fee when no compressed
3814
+ * 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
3815
  proveBatch({ queries, quantumResistant = true, compress: compress2 = true, idempotencyKey, retry = true }) {
3805
3816
  return this._t.request(
3806
3817
  this._base,
@@ -3815,7 +3826,8 @@ var EnyalSubmodule = class {
3815
3826
  if (poseidonKeyHash) body.poseidon_key_hash = poseidonKeyHash;
3816
3827
  return this._t.request(this._base, "POST", "/api/v1/prove/share-combination", { body, idempotencyKey, retry });
3817
3828
  }
3818
- /** 2.1.0: enyal-client.js:483. ENFORCED (disclose_routes.py:274). */
3829
+ /** 2.1.0: enyal-client.js:483. ENFORCED (disclose_routes.py:274).
3830
+ * 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
3831
  disclose({ chunkIds, recipientPubkeyHex, purpose, idempotencyKey, retry = true }) {
3820
3832
  return this._t.request(
3821
3833
  this._base,
@@ -3833,7 +3845,9 @@ var EnyalSubmodule = class {
3833
3845
  { body: { chunk_ids: chunkIds, purpose }, idempotencyKey, retry }
3834
3846
  );
3835
3847
  }
3836
- /** ENFORCED (message_routes.py:312). */
3848
+ /** ENFORCED (message_routes.py:312). 10 joules. recipientAgentId is the recipient's JoulePAI WALLET ID — agent
3849
+ * names and other free-form ids are private labels and are not addressable (409). senderAgentId is your own
3850
+ * wallet id or a label your account holds. */
3837
3851
  sendMessage({ senderAgentId, threadId, recipientAgentId, messageType, payload, idempotencyKey, retry = true }) {
3838
3852
  return this._t.request(
3839
3853
  this._base,
@@ -3852,6 +3866,8 @@ var EnyalSubmodule = class {
3852
3866
  }
3853
3867
  );
3854
3868
  }
3869
+ /** Read your inbox with your OWN JoulePAI wallet id as agentId (or a label your account holds) — messages are
3870
+ * addressed to wallet ids; an id another account holds gets 403. */
3855
3871
  getInbox({ agentId, direction = "inbox", ...params } = {}) {
3856
3872
  return this._t.request(
3857
3873
  this._base,
@@ -3894,6 +3910,10 @@ var EnyalSubmodule = class {
3894
3910
  );
3895
3911
  }
3896
3912
  // ── reads ──
3913
+ /** GET /api/v1/account — id, tier, email_verified and wallet_id (the account's own JoulePAI wallet id). */
3914
+ getAccount() {
3915
+ return this._t.request(this._base, "GET", "/api/v1/account", {});
3916
+ }
3897
3917
  search({ idempotencyKey, retry = true, ...params } = {}) {
3898
3918
  return this._t.request(this._base, "GET", "/api/v1/search", { params, idempotencyKey, retry });
3899
3919
  }
@@ -4320,7 +4340,14 @@ var JoulepaiSubmodule = class {
4320
4340
  * failed | cancelled → the ledger leg settled but the anchor dead-lettered and will NOT reach the chain by
4321
4341
  * itself (escalate); none → no anchor attempted; unknown → a queue status the view does not recognise. A null
4322
4342
  * txid on a fresh read is NOT a missing or failed leg — read anchor. The trade-WIDE view — transferStatus()
4323
- * and depositStatus() show only your own leg. Parity with the MCP `trade_settlement` tool. Backend d9a8e60. */
4343
+ * and depositStatus() show only your own leg. Parity with the MCP `trade_settlement` tool. Backend d9a8e60.
4344
+ * CONTRACT SECTION (backend 79d33fb): top-level `contract` — the on-chain escrow CONTRACT's own legs, separate
4345
+ * from legs[]; they move no joules, so they never change settled / leg_count / all_anchored. `contract` is null
4346
+ * when no escrow contract was recorded — a LEDGER-LANE trade (the default lane, escrow_bsv_state "NO_CONTRACT"):
4347
+ * normal, and the settled legs[] are the record. Otherwise { version, state (latest), closed (a FINAL leg exists:
4348
+ * RELEASED | REFUNDED | SPLIT | TIMEOUT_REFUNDED | AUTO_REFUNDED; an administrative closure is not final),
4349
+ * closed_on_chain (that final leg is anchored), closing_txid, legs[{ state, txid, anchor (anchored | confirming |
4350
+ * unknown), final }] }. */
4324
4351
  tradeSettlement(matchId) {
4325
4352
  return this._t.request(this._base, "GET", "/wallet/trade/{mid}/settlement", { pathParams: { mid: matchId } });
4326
4353
  }
@@ -4759,7 +4786,7 @@ var RareeaiSubmodule = class _RareeaiSubmodule {
4759
4786
  };
4760
4787
 
4761
4788
  // index.js
4762
- var VERSION = "0.5.3";
4789
+ var VERSION = "0.5.8";
4763
4790
  var Client = class {
4764
4791
  /**
4765
4792
  * @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.8";
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.6",
3
+ "version": "0.5.8",
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",
@@ -13,6 +13,9 @@ const DEFAULT_MAX_DELAY = 8000;
13
13
  const DEFAULT_BACKOFF_FACTOR = 2;
14
14
  const DEFAULT_JITTER_MIN = 100;
15
15
  const DEFAULT_JITTER_MAX = 300;
16
+ // A server Retry-After is honoured up to this many seconds. Longer is not slept through (it was uncapped: an ENYAL
17
+ // 'Retry-After: 3600' slept an hour per retry) — the error is thrown with .retryAfter so the caller decides.
18
+ const MAX_RETRY_AFTER_SECONDS = 60;
16
19
 
17
20
  const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
18
21
 
@@ -20,6 +23,19 @@ const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
20
23
  // credential is passed via the wrong parameter. Prefixed API keys (eyl_/gai_/…) never match
21
24
  // this (a JWT starts "eyJ"); only a bare JWT does. Routing itself is by parameter, not prefix.
22
25
  const JWT_RE = /^eyJ[\w-]*\.[\w-]+\.[\w-]+$/;
26
+ // What oauthToken accepts: a bare JWT, or ENYAL's OAuth access token, which ENYAL issues as `eyl_` + an RS256 JWT
27
+ // (enyal oauth_routes.py) and which every door reads as Bearer after stripping the prefix. An ENYAL API key is also
28
+ // `eyl_`-prefixed but is opaque (no dots), so it can never match and is still refused here (0.5.7).
29
+ const OAUTH_RE = /^(?:eyl_)?eyJ[\w-]*\.[\w-]+\.[\w-]+$/;
30
+
31
+ // Retry-After in seconds, or null. The header may also be an HTTP-date (RFC 9110 §10.2.3) or garbage; anything that is
32
+ // not a finite, non-negative number of seconds counts as ABSENT (ordinary backoff) and err.retryAfter is null, never
33
+ // NaN (P-DAY.122, Grok: Number() on an HTTP-date gave NaN; "Infinity" read as a wait longer than the cap).
34
+ function parseRetryAfter(value) {
35
+ if (value == null || value === "") return null;
36
+ const seconds = Number(value);
37
+ return Number.isFinite(seconds) && seconds >= 0 ? seconds : null;
38
+ }
23
39
 
24
40
  function isRetryable(err) {
25
41
  return err instanceof NetworkError || err instanceof RateLimitError || err instanceof ServerError;
@@ -39,7 +55,7 @@ export class Transport {
39
55
  if (JWT_RE.test(apiKey)) throw new Error("apiKey looks like a JWT (OAuth token) — pass it via oauthToken instead.");
40
56
  this._credential = apiKey; this._isApiKey = true;
41
57
  } 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.");
58
+ 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
59
  this._credential = oauthToken; this._isApiKey = false;
44
60
  }
45
61
  this.logger = logger || noopLogger;
@@ -94,7 +110,8 @@ export class Transport {
94
110
  return result;
95
111
  } catch (err) {
96
112
  if (err.statusCode === 401 && this.onAuthExpired) this.onAuthExpired(err); // §2: surface, never auto-refresh
97
- if (!retry || attempt >= maxRetries || !isRetryable(err)) {
113
+ const raTooLong = err.retryAfter != null && Number(err.retryAfter) > MAX_RETRY_AFTER_SECONDS;
114
+ if (!retry || attempt >= maxRetries || !isRetryable(err) || raTooLong) {
98
115
  if (this.onTerminalFailure) this.onTerminalFailure(err, attempt + 1);
99
116
  this.logger.warn(`terminal failure ${method} ${path} after ${attempt + 1} attempt(s)`);
100
117
  throw err;
@@ -130,7 +147,7 @@ export class Transport {
130
147
  }
131
148
  const requestId = resp.headers?.get ? resp.headers.get("x-request-id") : null;
132
149
  const ra = resp.headers?.get ? resp.headers.get("retry-after") : null;
133
- const retryAfter = ra ? Number(ra) : null;
150
+ const retryAfter = parseRetryAfter(ra);
134
151
  if (resp.status >= 400) {
135
152
  let detail;
136
153
  try { const data = await resp.json(); detail = data.detail ?? resp.statusText; }
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 });
@@ -79,7 +83,9 @@ export class EnyalSubmodule {
79
83
  { body: { chunk_ids: chunkIds, purpose }, idempotencyKey, retry });
80
84
  }
81
85
 
82
- /** ENFORCED (message_routes.py:312). */
86
+ /** ENFORCED (message_routes.py:312). 10 joules. recipientAgentId is the recipient's JoulePAI WALLET ID — agent
87
+ * names and other free-form ids are private labels and are not addressable (409). senderAgentId is your own
88
+ * wallet id or a label your account holds. */
83
89
  sendMessage({ senderAgentId, threadId, recipientAgentId, messageType, payload, idempotencyKey, retry = true }) {
84
90
  return this._t.request(this._base, "POST", "/api/v1/message/send",
85
91
  { body: { sender_agent_id: senderAgentId, thread_id: threadId,
@@ -87,6 +93,8 @@ export class EnyalSubmodule {
87
93
  idempotencyKey, retry });
88
94
  }
89
95
 
96
+ /** Read your inbox with your OWN JoulePAI wallet id as agentId (or a label your account holds) — messages are
97
+ * addressed to wallet ids; an id another account holds gets 403. */
90
98
  getInbox({ agentId, direction = "inbox", ...params } = {}) {
91
99
  return this._t.request(this._base, "GET", "/api/v1/message/inbox",
92
100
  { params: { agent_id: agentId, direction, ...params } });
@@ -119,6 +127,11 @@ export class EnyalSubmodule {
119
127
  }
120
128
 
121
129
  // ── reads ──
130
+ /** GET /api/v1/account — id, tier, email_verified and wallet_id (the account's own JoulePAI wallet id). */
131
+ getAccount() {
132
+ return this._t.request(this._base, "GET", "/api/v1/account", {});
133
+ }
134
+
122
135
  search({ idempotencyKey, retry = true, ...params } = {}) {
123
136
  return this._t.request(this._base, "GET", "/api/v1/search", { params, idempotencyKey, retry });
124
137
  }
package/src/joulepai.js CHANGED
@@ -68,7 +68,14 @@ export class JoulepaiSubmodule {
68
68
  * failed | cancelled → the ledger leg settled but the anchor dead-lettered and will NOT reach the chain by
69
69
  * itself (escalate); none → no anchor attempted; unknown → a queue status the view does not recognise. A null
70
70
  * txid on a fresh read is NOT a missing or failed leg — read anchor. The trade-WIDE view — transferStatus()
71
- * and depositStatus() show only your own leg. Parity with the MCP `trade_settlement` tool. Backend d9a8e60. */
71
+ * and depositStatus() show only your own leg. Parity with the MCP `trade_settlement` tool. Backend d9a8e60.
72
+ * CONTRACT SECTION (backend 79d33fb): top-level `contract` — the on-chain escrow CONTRACT's own legs, separate
73
+ * from legs[]; they move no joules, so they never change settled / leg_count / all_anchored. `contract` is null
74
+ * when no escrow contract was recorded — a LEDGER-LANE trade (the default lane, escrow_bsv_state "NO_CONTRACT"):
75
+ * normal, and the settled legs[] are the record. Otherwise { version, state (latest), closed (a FINAL leg exists:
76
+ * RELEASED | REFUNDED | SPLIT | TIMEOUT_REFUNDED | AUTO_REFUNDED; an administrative closure is not final),
77
+ * closed_on_chain (that final leg is anchored), closing_txid, legs[{ state, txid, anchor (anchored | confirming |
78
+ * unknown), final }] }. */
72
79
  tradeSettlement(matchId) {
73
80
  return this._t.request(this._base, "GET", "/wallet/trade/{mid}/settlement", { pathParams: { mid: matchId } });
74
81
  }