@greenlandai/sdk 0.5.17 → 3.0.1
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 +18 -0
- package/README.md +12 -0
- package/dist/index.cjs +76 -15
- package/index.js +1 -1
- package/package.json +10 -1
- package/src/core/crypto.js +7 -1
- package/src/core/messaging_client.js +304 -0
- package/src/core/messaging_store_node.js +94 -0
- package/src/core/messaging_v4.js +532 -0
- package/src/enyal.js +30 -5
- package/src/gldai.js +15 -4
- package/src/joulepai.js +14 -1
- package/src/rareeai.js +9 -4
package/src/enyal.js
CHANGED
|
@@ -98,16 +98,41 @@ export class EnyalSubmodule {
|
|
|
98
98
|
}
|
|
99
99
|
|
|
100
100
|
/** Read your inbox with your OWN JoulePAI wallet id as agentId (or a label your account holds) — messages are
|
|
101
|
-
* addressed to wallet ids; an id another account holds gets 403.
|
|
102
|
-
|
|
103
|
-
|
|
101
|
+
* addressed to wallet ids; an id another account holds gets 403. Received messages are then acknowledged
|
|
102
|
+
* (ackMessages) so their senders see Delivered; ack: false reads without acknowledging. The result carries
|
|
103
|
+
* acked (newly marked) or ack_error. */
|
|
104
|
+
async getInbox({ agentId, direction = "inbox", ack = true, ...params } = {}) {
|
|
105
|
+
const res = await this._t.request(this._base, "GET", "/api/v1/message/inbox",
|
|
104
106
|
{ params: { agent_id: agentId, direction, ...params } });
|
|
107
|
+
return ack && direction !== "outbox" ? this._ackAfterRead(res) : res;
|
|
105
108
|
}
|
|
106
109
|
|
|
107
|
-
|
|
110
|
+
/** The messages of a thread; the ones addressed to you are then acknowledged (see getInbox; ack: false skips it). */
|
|
111
|
+
async getThread(threadId, { copy, ack = true } = {}) {
|
|
108
112
|
// P-DAY.83 Option C: copy='sender' returns the sender's own ciphertext copy.
|
|
109
|
-
|
|
113
|
+
const res = await this._t.request(this._base, "GET", "/api/v1/message/thread/{thread_id}",
|
|
110
114
|
{ pathParams: { thread_id: threadId }, params: copy ? { copy } : {} });
|
|
115
|
+
return ack ? this._ackAfterRead(res) : res;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/** The "got it" receipt: POST /api/v1/message/ack sets delivered_at (the sender's Delivered) on the messages addressed
|
|
119
|
+
* to you; reading the inbox does not (since 2026-10-10 a read writes nothing). Never marks them read. Free; safe to repeat. */
|
|
120
|
+
ackMessages(messageIds, retry = true) {
|
|
121
|
+
return this._t.request(this._base, "POST", "/api/v1/message/ack",
|
|
122
|
+
{ body: { message_ids: messageIds }, retry });
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// P-DAY.131 (operator: "all 4 SDK packages call POST /message/ack"): ack the read messages not yet delivered. The server
|
|
126
|
+
// marks only the caller's own received rows. A failed ack never loses the read: ack_error is set and the next read retries.
|
|
127
|
+
async _ackAfterRead(res) {
|
|
128
|
+
const ids = ((res && res.messages) || []).filter((m) => m && m.message_id && !m.delivered_at).map((m) => m.message_id);
|
|
129
|
+
if (!ids.length) return res;
|
|
130
|
+
try {
|
|
131
|
+
res.acked = (await this.ackMessages(ids)).updated;
|
|
132
|
+
} catch (e) {
|
|
133
|
+
res.ack_error = (e && e.message) || String(e);
|
|
134
|
+
}
|
|
135
|
+
return res;
|
|
111
136
|
}
|
|
112
137
|
|
|
113
138
|
/** P-DAY.83 Option C: the caller's own customer-wrapped custodial blob for
|
package/src/gldai.js
CHANGED
|
@@ -25,7 +25,9 @@ export class GldaiSubmodule {
|
|
|
25
25
|
constructor(transport, baseUrl = GLDAI_BASE) {
|
|
26
26
|
this._t = transport; this._base = baseUrl;
|
|
27
27
|
}
|
|
28
|
-
/** GET /api/v1/companies (Class C, metered): charged_joules + the metering block (file header — read metering.settlement to know whether you paid).
|
|
28
|
+
/** GET /api/v1/companies (Class C, metered): charged_joules + the metering block (file header — read metering.settlement to know whether you paid).
|
|
29
|
+
* `country` matches on the country code: "USA", "US" and "United States" find the same rows, "Chile,Peru" finds either,
|
|
30
|
+
* an unrecognised value is a partial-name match. Each company carries `country` and `country_code` (ISO 3166-1 alpha-2; null for a multi-country row). */
|
|
29
31
|
companies({ idempotencyKey, ...params } = {}) {
|
|
30
32
|
return this._t.request(this._base, "GET", "/api/v1/companies", { params, idempotencyKey });
|
|
31
33
|
}
|
|
@@ -42,7 +44,11 @@ export class GldaiSubmodule {
|
|
|
42
44
|
* `commodity_filter` {query, matched_directly, matched_via_group} tells you which (matched_via_group
|
|
43
45
|
* names the group). Each deposit carries `commodities[]` {name, role:primary|byproduct, group};
|
|
44
46
|
* resource_type stays primary. The response also carries `charged_joules` (all-in metered cost; null
|
|
45
|
-
* for a quota caller) and the metering block (file header). R6-C, 2026-09-22.
|
|
47
|
+
* for a quota caller) and the metering block (file header). R6-C, 2026-09-22.
|
|
48
|
+
* `country` / `owner_country` match on the country code: "USA", "US" and "United States" find the same rows, "Chile,Peru"
|
|
49
|
+
* finds either, an unrecognised value is a partial-name match. Each deposit carries `country`, `country_code` (ISO 3166-1
|
|
50
|
+
* alpha-2; null for a multi-country row), `country_codes`, `country_scope`, `country_input` (the text as the source stated
|
|
51
|
+
* it) and the same five for the owner (`owner_country_*`). */
|
|
46
52
|
deposits({ idempotencyKey, ...params } = {}) {
|
|
47
53
|
return this._t.request(this._base, "GET", "/api/v1/deposits", { params, idempotencyKey });
|
|
48
54
|
}
|
|
@@ -50,7 +56,10 @@ export class GldaiSubmodule {
|
|
|
50
56
|
deposit(depositId) {
|
|
51
57
|
return this._t.request(this._base, "GET", "/api/v1/deposits/{did}", { pathParams: { did: depositId } });
|
|
52
58
|
}
|
|
53
|
-
/** GET /api/v1/infrastructure (Class C, metered): charged_joules + metering block (file header).
|
|
59
|
+
/** GET /api/v1/infrastructure (Class C, metered): charged_joules + metering block (file header).
|
|
60
|
+
* `country` / `owner_country` match on the country code ("USA", "US" and "United States" find the same rows; "Chile,Peru"
|
|
61
|
+
* finds either; an unrecognised value is a partial-name match). Each asset carries `country`, `country_code` (ISO 3166-1
|
|
62
|
+
* alpha-2; null for a multi-country row), `country_codes`, `country_scope`, `country_input` and the same five for the owner. */
|
|
54
63
|
infrastructureList({ idempotencyKey, ...params } = {}) {
|
|
55
64
|
return this._t.request(this._base, "GET", "/api/v1/infrastructure", { params, idempotencyKey });
|
|
56
65
|
}
|
|
@@ -67,7 +76,9 @@ export class GldaiSubmodule {
|
|
|
67
76
|
query(q, { idempotencyKey, ...params } = {}) {
|
|
68
77
|
return this._t.request(this._base, "GET", "/api/v1/query", { params: { q, ...params }, idempotencyKey });
|
|
69
78
|
}
|
|
70
|
-
/** GET /api/v1/projects (Class C, metered): charged_joules + metering block (file header).
|
|
79
|
+
/** GET /api/v1/projects (Class C, metered): charged_joules + metering block (file header).
|
|
80
|
+
* `country` matches on the country code ("USA", "US" and "United States" find the same rows; "Chile,Peru" finds either;
|
|
81
|
+
* an unrecognised value is a partial-name match). Each project carries `country` and `country_code`. */
|
|
71
82
|
projects({ idempotencyKey, ...params } = {}) {
|
|
72
83
|
return this._t.request(this._base, "GET", "/api/v1/projects", { params, idempotencyKey });
|
|
73
84
|
}
|
package/src/joulepai.js
CHANGED
|
@@ -22,7 +22,10 @@ export class JoulepaiSubmodule {
|
|
|
22
22
|
return this._walletId;
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
/** Absorbs Wallet.create (index.js:50).
|
|
25
|
+
/** Absorbs Wallet.create (index.js:50). A SIGNED-IN SESSION, or an agent key its owner granted the custom scope
|
|
26
|
+
* `wallet:create`: build the Client with your signed-in session (oauthToken: the ENYAL session from sign-in, or
|
|
27
|
+
* joulepai.ai's own session JWT). Any other API key or OAuth token is refused 403 {"error":"scope_not_granted",
|
|
28
|
+
* "scope":"wallet:create"} (ScopeError) — a person's own jlp_ wallet key carries no grant. POST /wallet/create. */
|
|
26
29
|
createWallet({ email, ownerId, ownerType = "human", handle }) {
|
|
27
30
|
const body = { owner_id: ownerId || crypto.randomUUID(), owner_type: ownerType, email };
|
|
28
31
|
if (handle) body.handle = handle;
|
|
@@ -124,6 +127,9 @@ export class JoulepaiSubmodule {
|
|
|
124
127
|
{ pathParams: { wid: await this._ensureId() }, params: { limit, offset } });
|
|
125
128
|
}
|
|
126
129
|
|
|
130
|
+
/** Set your wallet's handle. SESSION-ONLY — build the Client with your signed-in session (oauthToken: the ENYAL
|
|
131
|
+
* session from sign-in, or joulepai.ai's own session JWT), NOT an API key or OAuth token (refused 403
|
|
132
|
+
* {"error":"session_required"}, ScopeError). PUT /wallet/handle. */
|
|
127
133
|
async setHandle(h) {
|
|
128
134
|
return this._t.request(this._base, "PUT", "/wallet/handle",
|
|
129
135
|
{ body: { wallet_id: await this._ensureId(), handle: h.replace(/^@/, "") } });
|
|
@@ -139,6 +145,9 @@ export class JoulepaiSubmodule {
|
|
|
139
145
|
{ pathParams: { wid: await this._ensureId() } });
|
|
140
146
|
}
|
|
141
147
|
|
|
148
|
+
/** Set the wallet's spending limits. SESSION-ONLY — build the Client with your signed-in session (oauthToken: the
|
|
149
|
+
* ENYAL session from sign-in, or joulepai.ai's own session JWT), NOT an API key or OAuth token (refused 403
|
|
150
|
+
* {"error":"session_required"}, ScopeError). Reading them (getLimits) is unchanged. PUT /wallet/limits. */
|
|
142
151
|
async setLimits({ daily, perTransaction, allowedPlatforms } = {}) {
|
|
143
152
|
const body = { agent_wallet_id: await this._ensureId() };
|
|
144
153
|
if (daily != null) body.daily_cap = daily;
|
|
@@ -203,6 +212,10 @@ export class JoulepaiSubmodule {
|
|
|
203
212
|
};
|
|
204
213
|
}
|
|
205
214
|
|
|
215
|
+
/** For a lost API key; no sign-in needed (the wallet id + the wallet's email). Nothing is rotated and no key is sent:
|
|
216
|
+
* the wallet's email is told how to get a new key — sign in at joulepai.ai, Dashboard → API Credentials
|
|
217
|
+
* (POST /wallet/regenerate-key, signed-in owner only), where the new key is shown once. The current key keeps working
|
|
218
|
+
* until then. POST /wallet/reset-credentials. */
|
|
206
219
|
resetCredentials(walletId, email) {
|
|
207
220
|
return this._t.request(this._base, "POST", "/wallet/reset-credentials",
|
|
208
221
|
{ body: { wallet_id: walletId, email } });
|
package/src/rareeai.js
CHANGED
|
@@ -44,10 +44,11 @@ export class RareeaiSubmodule {
|
|
|
44
44
|
"timeout_hours", "timeout_minutes", "stake_amount", "oracle_verified", "idempotency_key"]),
|
|
45
45
|
request: new Set(["wallet_id", "frontier", "resource_type", "unit_type", "units_needed",
|
|
46
46
|
"max_price_per_unit", "priority", "requirements", "ttl_seconds", "speed", "privacy_mode",
|
|
47
|
-
"contract_escrow", "idempotency_key"
|
|
47
|
+
"contract_escrow", "physical_claim", "idempotency_key",
|
|
48
|
+
"provider_id"]), // P-DAY.133 item 3: RAREEAI honours it (matches that listing only; 404 when invalid)
|
|
48
49
|
dispute: new Set(["reason"]),
|
|
49
50
|
resolve: new Set(["resolution", "split_pct"]),
|
|
50
|
-
deliver: new Set(), approve: new Set(), reject: new Set(), extend_dispute: new Set(),
|
|
51
|
+
deliver: new Set(), approve: new Set(), reject: new Set(), extend_dispute: new Set(["until"]),
|
|
51
52
|
};
|
|
52
53
|
/** Keep only fields the backend model for `kind` accepts; refuse the rest by name. */
|
|
53
54
|
static _body(kind, fields) {
|
|
@@ -70,6 +71,8 @@ export class RareeaiSubmodule {
|
|
|
70
71
|
}
|
|
71
72
|
// ENFORCED-WHEN-PRESENT / BEST-EFFORT-keyless (routes.py:1282 guard; SDK dispatch
|
|
72
73
|
// always auto-gens a key → SDK callers effectively enforced; keyless gap raw-HTTP-only).
|
|
74
|
+
// 0.5.18: resourceType scene_stack / change_report / site_reconstruction / satellite_imagery MUST pass physical_claim
|
|
75
|
+
// { kind: 'physical_change'|'physical_state', site_lat, site_lng, t1, t0 (a change), radius_m? } — RAREEAI refuses it otherwise.
|
|
73
76
|
createRequest({ resourceType, idempotencyKey, retry = true, ...fields }) {
|
|
74
77
|
return this._t.request(this._base, "POST", `${this._p}/request`,
|
|
75
78
|
{ body: { resource_type: resourceType, ...RareeaiSubmodule._body("request", fields) }, idempotencyKey, retry });
|
|
@@ -110,9 +113,11 @@ export class RareeaiSubmodule {
|
|
|
110
113
|
return this._t.request(this._base, "POST", `${this._p}/match/{match_id}/dispute`,
|
|
111
114
|
{ pathParams: { match_id: matchId }, body: RareeaiSubmodule._body("dispute", fields) });
|
|
112
115
|
}
|
|
113
|
-
|
|
116
|
+
// Offer, or agree to, a FIXED later dispute deadline (P-DAY.133): both parties send the same `until` (ISO 8601 with a timezone);
|
|
117
|
+
// the first call is an offer, the other party's identical call is the extension. NOT retry-safe.
|
|
118
|
+
extendDispute(matchId, until, fields = {}) {
|
|
114
119
|
return this._t.request(this._base, "POST", `${this._p}/match/{match_id}/extend-dispute`,
|
|
115
|
-
{ pathParams: { match_id: matchId }, body: RareeaiSubmodule._body("extend_dispute", fields) });
|
|
120
|
+
{ pathParams: { match_id: matchId }, body: RareeaiSubmodule._body("extend_dispute", { until, ...fields }) });
|
|
116
121
|
}
|
|
117
122
|
|
|
118
123
|
// reads
|