@greenlandai/sdk 0.5.7 → 0.5.9

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.9 (2026-09-28)
2
+ - Version parity with the Python package (greenlandai 0.5.9). No JavaScript change: the encrypted knowledge-graph backup
3
+ (`sync_to_enyal()` / `restore_from_enyal()`) exists only in the Python `EnyalAgent`; JavaScript users have it in @enyalai/sdk.
4
+
5
+ ## 0.5.8 (2026-09-28)
6
+ - **Fix: `EnyalAgent` (Python) no longer archives under the fixed ids `sdk-agent` / `sdk-sync`.** ENYAL now refuses an
7
+ agent id another account already holds (403), so a fixed id shared by every customer belonged to the first account
8
+ to use it. The default is the account's OWN JoulePAI wallet id (looked up once via `GET /api/v1/account`); an
9
+ account with no wallet must pass an agent_id of its own. `inbox()` with no agent_id reads the own wallet id.
10
+ - **Fix: `Retry-After` was honoured with no upper limit** — ENYAL's `Retry-After: 3600` slept an hour per retry. Now
11
+ honoured up to 60 seconds; longer is not slept through — the error is raised with `retry_after` set (both languages).
12
+ - **Fix: a `Retry-After` that is not a number of seconds no longer breaks the call.** The header may be an HTTP-date
13
+ (RFC 9110); Python raised `ValueError` on any response carrying one (even a 200), and JS set `retryAfter` to
14
+ `NaN`. Anything that is not a finite, non-negative number of seconds now counts as absent: ordinary backoff, and
15
+ `retry_after` / `retryAfter` is `None` / `null` (both languages).
16
+ - Added `client.enyal.get_account()` / `getAccount()` — `GET /api/v1/account` (id, tier, `wallet_id`, …).
17
+ - Docs: messages are addressed by the recipient's JoulePAI wallet id (agent names and free-form ids are private labels
18
+ and get 409); read your inbox with your own wallet id. README examples use a placeholder agent id and say it must be
19
+ your own.
20
+
1
21
  ## 0.5.7 (2026-09-23)
2
22
  - **Fix: an ENYAL OAuth access token is accepted as the OAuth credential.** ENYAL issues it as `eyl_` + a JWT;
3
23
  `oauth_token` / `oauthToken` accepted only a bare JWT (`eyJ…`) and raised, pushing agents onto the API-key
package/README.md CHANGED
@@ -29,7 +29,10 @@ const client = new Client({ oauthToken: jwt }); // an OAuth JWT — bare, o
29
29
 
30
30
  ## Hello world (one per submodule)
31
31
  ```js
32
- await client.enyal.archive({ agentId: "agent-1", chunkType: "decision_record", chunkKey: "k1", data: { decision: "x" } });
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" } });
33
36
  await client.joulepai.transfer("@bob", 1000, { note: "thanks" }); // auto idempotency key
34
37
  await client.rareeai.createRequest({ resourceType: "gpu" }); // marketplace (flat 1%, floor 50 J — parse fee_joules)
35
38
  await client.rareeai.oracleAssignments(); // oracle queue (0.3.6; the pool is invite-only at launch)
package/dist/index.cjs CHANGED
@@ -167,9 +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-]+$/;
172
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
+ }
173
179
  function isRetryable(err) {
174
180
  return err instanceof NetworkError || err instanceof RateLimitError || err instanceof ServerError;
175
181
  }
@@ -252,7 +258,8 @@ var Transport = class {
252
258
  return result;
253
259
  } catch (err) {
254
260
  if (err.statusCode === 401 && this.onAuthExpired) this.onAuthExpired(err);
255
- 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) {
256
263
  if (this.onTerminalFailure) this.onTerminalFailure(err, attempt + 1);
257
264
  this.logger.warn(`terminal failure ${method} ${path} after ${attempt + 1} attempt(s)`);
258
265
  throw err;
@@ -286,7 +293,7 @@ var Transport = class {
286
293
  }
287
294
  const requestId = resp.headers?.get ? resp.headers.get("x-request-id") : null;
288
295
  const ra = resp.headers?.get ? resp.headers.get("retry-after") : null;
289
- const retryAfter = ra ? Number(ra) : null;
296
+ const retryAfter = parseRetryAfter(ra);
290
297
  if (resp.status >= 400) {
291
298
  let detail;
292
299
  try {
@@ -3838,7 +3845,9 @@ var EnyalSubmodule = class {
3838
3845
  { body: { chunk_ids: chunkIds, purpose }, idempotencyKey, retry }
3839
3846
  );
3840
3847
  }
3841
- /** 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. */
3842
3851
  sendMessage({ senderAgentId, threadId, recipientAgentId, messageType, payload, idempotencyKey, retry = true }) {
3843
3852
  return this._t.request(
3844
3853
  this._base,
@@ -3857,6 +3866,8 @@ var EnyalSubmodule = class {
3857
3866
  }
3858
3867
  );
3859
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. */
3860
3871
  getInbox({ agentId, direction = "inbox", ...params } = {}) {
3861
3872
  return this._t.request(
3862
3873
  this._base,
@@ -3899,6 +3910,10 @@ var EnyalSubmodule = class {
3899
3910
  );
3900
3911
  }
3901
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
+ }
3902
3917
  search({ idempotencyKey, retry = true, ...params } = {}) {
3903
3918
  return this._t.request(this._base, "GET", "/api/v1/search", { params, idempotencyKey, retry });
3904
3919
  }
@@ -4325,7 +4340,14 @@ var JoulepaiSubmodule = class {
4325
4340
  * failed | cancelled → the ledger leg settled but the anchor dead-lettered and will NOT reach the chain by
4326
4341
  * itself (escalate); none → no anchor attempted; unknown → a queue status the view does not recognise. A null
4327
4342
  * txid on a fresh read is NOT a missing or failed leg — read anchor. The trade-WIDE view — transferStatus()
4328
- * 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 }] }. */
4329
4351
  tradeSettlement(matchId) {
4330
4352
  return this._t.request(this._base, "GET", "/wallet/trade/{mid}/settlement", { pathParams: { mid: matchId } });
4331
4353
  }
@@ -4764,7 +4786,7 @@ var RareeaiSubmodule = class _RareeaiSubmodule {
4764
4786
  };
4765
4787
 
4766
4788
  // index.js
4767
- var VERSION = "0.5.7";
4789
+ var VERSION = "0.5.9";
4768
4790
  var Client = class {
4769
4791
  /**
4770
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.7";
19
+ export const VERSION = "0.5.9";
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.7",
3
+ "version": "0.5.9",
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
 
@@ -25,6 +28,15 @@ const JWT_RE = /^eyJ[\w-]*\.[\w-]+\.[\w-]+$/;
25
28
  // `eyl_`-prefixed but is opaque (no dots), so it can never match and is still refused here (0.5.7).
26
29
  const OAUTH_RE = /^(?:eyl_)?eyJ[\w-]*\.[\w-]+\.[\w-]+$/;
27
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
+ }
39
+
28
40
  function isRetryable(err) {
29
41
  return err instanceof NetworkError || err instanceof RateLimitError || err instanceof ServerError;
30
42
  }
@@ -98,7 +110,8 @@ export class Transport {
98
110
  return result;
99
111
  } catch (err) {
100
112
  if (err.statusCode === 401 && this.onAuthExpired) this.onAuthExpired(err); // §2: surface, never auto-refresh
101
- 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) {
102
115
  if (this.onTerminalFailure) this.onTerminalFailure(err, attempt + 1);
103
116
  this.logger.warn(`terminal failure ${method} ${path} after ${attempt + 1} attempt(s)`);
104
117
  throw err;
@@ -134,7 +147,7 @@ export class Transport {
134
147
  }
135
148
  const requestId = resp.headers?.get ? resp.headers.get("x-request-id") : null;
136
149
  const ra = resp.headers?.get ? resp.headers.get("retry-after") : null;
137
- const retryAfter = ra ? Number(ra) : null;
150
+ const retryAfter = parseRetryAfter(ra);
138
151
  if (resp.status >= 400) {
139
152
  let detail;
140
153
  try { const data = await resp.json(); detail = data.detail ?? resp.statusText; }
package/src/enyal.js CHANGED
@@ -83,7 +83,9 @@ export class EnyalSubmodule {
83
83
  { body: { chunk_ids: chunkIds, purpose }, idempotencyKey, retry });
84
84
  }
85
85
 
86
- /** 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. */
87
89
  sendMessage({ senderAgentId, threadId, recipientAgentId, messageType, payload, idempotencyKey, retry = true }) {
88
90
  return this._t.request(this._base, "POST", "/api/v1/message/send",
89
91
  { body: { sender_agent_id: senderAgentId, thread_id: threadId,
@@ -91,6 +93,8 @@ export class EnyalSubmodule {
91
93
  idempotencyKey, retry });
92
94
  }
93
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. */
94
98
  getInbox({ agentId, direction = "inbox", ...params } = {}) {
95
99
  return this._t.request(this._base, "GET", "/api/v1/message/inbox",
96
100
  { params: { agent_id: agentId, direction, ...params } });
@@ -123,6 +127,11 @@ export class EnyalSubmodule {
123
127
  }
124
128
 
125
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
+
126
135
  search({ idempotencyKey, retry = true, ...params } = {}) {
127
136
  return this._t.request(this._base, "GET", "/api/v1/search", { params, idempotencyKey, retry });
128
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
  }