@greenlandai/sdk 0.5.2 → 0.5.4
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/dist/index.cjs +317 -208
- package/index.js +1 -1
- package/package.json +2 -2
- package/src/core/idempotency.js +1 -0
- package/src/core/transport.js +24 -3
- package/src/gldai.js +35 -1
- package/src/joulepai.js +58 -3
package/dist/index.cjs
CHANGED
|
@@ -117,6 +117,7 @@ var IDEMPOTENCY_MAP = {
|
|
|
117
117
|
"GET /api/v1/nearby": { field: "X-Idempotency-Key", placement: "header", tier: ENFORCED },
|
|
118
118
|
"GET /api/v1/relationships": { field: "X-Idempotency-Key", placement: "header", tier: ENFORCED },
|
|
119
119
|
"GET /api/v1/map.viewport": { field: "X-Idempotency-Key", placement: "header", tier: ENFORCED },
|
|
120
|
+
"GET /api/v1/look.at": { field: "X-Idempotency-Key", placement: "header", tier: ENFORCED },
|
|
120
121
|
// (cf) ENYAL metered GET — joins Class C header class (server reads X-Idempotency-Key per the Option-B switch)
|
|
121
122
|
"GET /api/v1/search": { field: "X-Idempotency-Key", placement: "header", tier: ENFORCED },
|
|
122
123
|
// Class D — transfer-class
|
|
@@ -205,13 +206,22 @@ var Transport = class {
|
|
|
205
206
|
this.metrics = metrics || null;
|
|
206
207
|
this._fetch = fetchImpl || fetch;
|
|
207
208
|
}
|
|
209
|
+
/** True when the credential is a GreenlandAI agent API key (gai_/gqa_). Used ONLY to choose which
|
|
210
|
+
* backend serves this key's OWN wallet balance (GreenlandAI's free agent-self endpoint vs JoulePAI) —
|
|
211
|
+
* NOT for auth-header selection, which stays parameter-based (§2). A gai_/gqa_ key has no JoulePAI
|
|
212
|
+
* wallet row; its balance lives at GET /api/v1/agent/me/balance (free). */
|
|
213
|
+
get isGreenlandaiAgentKey() {
|
|
214
|
+
return this._isApiKey && (this._credential.startsWith("gai_") || this._credential.startsWith("gqa_"));
|
|
215
|
+
}
|
|
208
216
|
async request(baseUrl, method, pathTemplate, {
|
|
209
217
|
pathParams = {},
|
|
210
218
|
body = null,
|
|
211
219
|
params = null,
|
|
212
220
|
idempotencyKey = null,
|
|
213
221
|
retry = true,
|
|
214
|
-
maxRetries = DEFAULT_MAX_RETRIES
|
|
222
|
+
maxRetries = DEFAULT_MAX_RETRIES,
|
|
223
|
+
accept = null,
|
|
224
|
+
raw = false
|
|
215
225
|
} = {}) {
|
|
216
226
|
let headers = this._isApiKey ? { "X-API-Key": this._credential } : { Authorization: `Bearer ${this._credential}` };
|
|
217
227
|
const d = dispatch(method, pathTemplate, body, headers, idempotencyKey);
|
|
@@ -231,7 +241,7 @@ var Transport = class {
|
|
|
231
241
|
const t0 = Date.now();
|
|
232
242
|
for (; ; ) {
|
|
233
243
|
try {
|
|
234
|
-
const result = await this._once(method, url, headers, body);
|
|
244
|
+
const result = await this._once(method, url, headers, body, { accept, raw });
|
|
235
245
|
this._count("sdk.requests");
|
|
236
246
|
this._hist("sdk.request.duration", (Date.now() - t0) / 1e3);
|
|
237
247
|
if (result && result.duplicate === true) {
|
|
@@ -256,7 +266,7 @@ var Transport = class {
|
|
|
256
266
|
}
|
|
257
267
|
}
|
|
258
268
|
}
|
|
259
|
-
async _once(method, url, headers, body) {
|
|
269
|
+
async _once(method, url, headers, body, { accept = null, raw = false } = {}) {
|
|
260
270
|
const redacted = { ...headers };
|
|
261
271
|
if ("Authorization" in redacted) redacted.Authorization = "[REDACTED]";
|
|
262
272
|
if ("X-API-Key" in redacted) redacted["X-API-Key"] = "[REDACTED]";
|
|
@@ -264,6 +274,7 @@ var Transport = class {
|
|
|
264
274
|
let resp;
|
|
265
275
|
try {
|
|
266
276
|
const opts2 = { method, headers: { ...headers } };
|
|
277
|
+
if (accept) opts2.headers["Accept"] = accept;
|
|
267
278
|
if (body != null) {
|
|
268
279
|
opts2.headers["Content-Type"] = "application/json";
|
|
269
280
|
opts2.body = JSON.stringify(body);
|
|
@@ -286,6 +297,16 @@ var Transport = class {
|
|
|
286
297
|
if (typeof detail === "object") detail = JSON.stringify(detail);
|
|
287
298
|
throw errorForStatus(resp.status, String(detail), requestId, retryAfter);
|
|
288
299
|
}
|
|
300
|
+
if (raw) {
|
|
301
|
+
const ct = resp.headers?.get ? resp.headers.get("content-type") || "" : "";
|
|
302
|
+
if (ct.startsWith("application/json")) return resp.json();
|
|
303
|
+
const buf = await resp.arrayBuffer();
|
|
304
|
+
const provenance = {};
|
|
305
|
+
if (resp.headers?.forEach) resp.headers.forEach((v, k) => {
|
|
306
|
+
if (k.toLowerCase().startsWith("x-")) provenance[k] = v;
|
|
307
|
+
});
|
|
308
|
+
return { _raw: true, content_type: ct, content: new Uint8Array(buf), provenance };
|
|
309
|
+
}
|
|
289
310
|
if (resp.status === 204) return null;
|
|
290
311
|
return resp.json();
|
|
291
312
|
}
|
|
@@ -3967,6 +3988,245 @@ var EnyalSubmodule = class {
|
|
|
3967
3988
|
}
|
|
3968
3989
|
};
|
|
3969
3990
|
|
|
3991
|
+
// src/gldai.js
|
|
3992
|
+
var GLDAI_BASE = "https://greenlandai.ai";
|
|
3993
|
+
var GldaiSubmodule = class {
|
|
3994
|
+
constructor(transport, baseUrl = GLDAI_BASE) {
|
|
3995
|
+
this._t = transport;
|
|
3996
|
+
this._base = baseUrl;
|
|
3997
|
+
}
|
|
3998
|
+
companies({ idempotencyKey, ...params } = {}) {
|
|
3999
|
+
return this._t.request(this._base, "GET", "/api/v1/companies", { params, idempotencyKey });
|
|
4000
|
+
}
|
|
4001
|
+
company(companyId) {
|
|
4002
|
+
return this._t.request(this._base, "GET", "/api/v1/companies/{cid}", { pathParams: { cid: companyId } });
|
|
4003
|
+
}
|
|
4004
|
+
deposits({ idempotencyKey, ...params } = {}) {
|
|
4005
|
+
return this._t.request(this._base, "GET", "/api/v1/deposits", { params, idempotencyKey });
|
|
4006
|
+
}
|
|
4007
|
+
deposit(depositId) {
|
|
4008
|
+
return this._t.request(this._base, "GET", "/api/v1/deposits/{did}", { pathParams: { did: depositId } });
|
|
4009
|
+
}
|
|
4010
|
+
infrastructureList({ idempotencyKey, ...params } = {}) {
|
|
4011
|
+
return this._t.request(this._base, "GET", "/api/v1/infrastructure", { params, idempotencyKey });
|
|
4012
|
+
}
|
|
4013
|
+
infrastructure(infraId) {
|
|
4014
|
+
return this._t.request(this._base, "GET", "/api/v1/infrastructure/{iid}", { pathParams: { iid: infraId } });
|
|
4015
|
+
}
|
|
4016
|
+
/** GET /api/v1/query — the natural-language intelligence query, metered per call (Class C). WORKS FOR
|
|
4017
|
+
* JOULE-METERED AGENTS: they pay per query and are EXEMPT from the human NL access gates (the old
|
|
4018
|
+
* charged-then-403 for agents was fixed; api.py:1414 `_is_joule_agent` bypasses the email-verify /
|
|
4019
|
+
* door / entitlement checks, which apply to human accounts only). Humans need a verified ENYAL
|
|
4020
|
+
* identity + NL access ($10/level). Metered against the CALLING agent's wallet — quote with
|
|
4021
|
+
* billingQuote("/api/v1/query") first. */
|
|
4022
|
+
query(q, { idempotencyKey, ...params } = {}) {
|
|
4023
|
+
return this._t.request(this._base, "GET", "/api/v1/query", { params: { q, ...params }, idempotencyKey });
|
|
4024
|
+
}
|
|
4025
|
+
projects({ idempotencyKey, ...params } = {}) {
|
|
4026
|
+
return this._t.request(this._base, "GET", "/api/v1/projects", { params, idempotencyKey });
|
|
4027
|
+
}
|
|
4028
|
+
project(projectId) {
|
|
4029
|
+
return this._t.request(this._base, "GET", "/api/v1/projects/{pid}", { pathParams: { pid: projectId } });
|
|
4030
|
+
}
|
|
4031
|
+
/** CLOSED — do NOT call. GET /api/v1/mapdata (the bulk map-layers surface) is closed to all callers and
|
|
4032
|
+
* returns an error. Use mapViewport() for map reads. Kept only so the method still resolves for older
|
|
4033
|
+
* callers. Matches the MCP `mapdata` tool (also marked CLOSED). */
|
|
4034
|
+
mapdata({ idempotencyKey, ...params } = {}) {
|
|
4035
|
+
return this._t.request(this._base, "GET", "/api/v1/mapdata", { params, idempotencyKey });
|
|
4036
|
+
}
|
|
4037
|
+
// ── pricing + live map/graph read surface (2026-09-14; parity with the MCP tools) ──
|
|
4038
|
+
/** The exact per-caller price of a metered call BEFORE you make it — GET /api/v1/billing/quote. FREE
|
|
4039
|
+
* (no charge), needs only a credential (no verification). `path` = the API path the call would hit
|
|
4040
|
+
* (e.g. "/api/v1/relationships", "/api/v1/look.from", "/api/v1/nearby", "/api/v1/companies/{id}",
|
|
4041
|
+
* "/api/v1/mapdata"); `hops` = graph depth 1-10 (your tier caps it — Pioneer/FC 3, TEN/Pro 5,
|
|
4042
|
+
* Enterprise 10) for a relationships path. Priced at YOUR tier.
|
|
4043
|
+
* Returns { joules (base), rail_fee_joules, joules_all_in, pricing_tier, usd, … } — joules_all_in is
|
|
4044
|
+
* the TRUE debit (base + the 0.5% rail surcharge), so fund THAT, not the base. Same helper as the MCP
|
|
4045
|
+
* `billing_quote` tool. Metered reads debit the CALLING agent's OWN wallet (not the owner's); read the
|
|
4046
|
+
* balance with client.joulepai.balance() and check affordability with client.joulepai.deficit(). */
|
|
4047
|
+
billingQuote(path, hops = null) {
|
|
4048
|
+
const params = hops == null ? { path } : { path, hops };
|
|
4049
|
+
return this._t.request(this._base, "GET", "/api/v1/billing/quote", { params });
|
|
4050
|
+
}
|
|
4051
|
+
/** GET /api/v1/look.from — companies/infrastructure near a point (lat+lng) or anchored on one entity
|
|
4052
|
+
* (entityType+id). Metered against the CALLING agent's wallet (base + 0.5% rail; quote with
|
|
4053
|
+
* billingQuote). entityType behaves two ways (backend 2026-09-14): entityType ALONE (with lat/lng)
|
|
4054
|
+
* FILTERS the frame to that type; entityType + id ANCHORS the pose at that entity and keeps ALL types;
|
|
4055
|
+
* an unknown entityType is a 400 before any charge. Same as the MCP `look_from` tool. */
|
|
4056
|
+
lookFrom({
|
|
4057
|
+
lat,
|
|
4058
|
+
lng,
|
|
4059
|
+
entityType,
|
|
4060
|
+
id,
|
|
4061
|
+
radiusKm = 100,
|
|
4062
|
+
energy = false,
|
|
4063
|
+
includeCountryCentroids = false,
|
|
4064
|
+
idempotencyKey
|
|
4065
|
+
} = {}) {
|
|
4066
|
+
const params = { radius_km: radiusKm, energy, include_country_centroids: includeCountryCentroids };
|
|
4067
|
+
if (lat != null) params.lat = lat;
|
|
4068
|
+
if (lng != null) params.lng = lng;
|
|
4069
|
+
if (entityType != null) params.entity_type = entityType;
|
|
4070
|
+
if (id != null) params.id = id;
|
|
4071
|
+
return this._t.request(this._base, "GET", "/api/v1/look.from", { params, idempotencyKey });
|
|
4072
|
+
}
|
|
4073
|
+
/** GET /api/v1/nearby — entities near a location; here entityType IS a content filter. Metered against
|
|
4074
|
+
* the CALLING agent's wallet (quote with billingQuote). Same as the MCP `nearby` tool. */
|
|
4075
|
+
nearby({
|
|
4076
|
+
lat,
|
|
4077
|
+
lng,
|
|
4078
|
+
radiusKm = 100,
|
|
4079
|
+
entityType,
|
|
4080
|
+
limit = 20,
|
|
4081
|
+
includeCountryCentroids = false,
|
|
4082
|
+
idempotencyKey
|
|
4083
|
+
} = {}) {
|
|
4084
|
+
const params = { lat, lng, radius_km: radiusKm, limit, include_country_centroids: includeCountryCentroids };
|
|
4085
|
+
if (entityType != null) params.entity_type = entityType;
|
|
4086
|
+
return this._t.request(this._base, "GET", "/api/v1/nearby", { params, idempotencyKey });
|
|
4087
|
+
}
|
|
4088
|
+
/** GET /api/v1/relationships — labelled relationship hops (the MCP `hops` tool). `entity` is the START
|
|
4089
|
+
* NODE, matched as a case-insensitive SUBSTRING of an entity NAME (never an id: "3" matches any name
|
|
4090
|
+
* containing "3"), so pass a full, distinctive name. `hops` = depth 1-10. Metered per hop against the
|
|
4091
|
+
* CALLING agent's wallet (quote with billingQuote("/api/v1/relationships", n)). */
|
|
4092
|
+
relationships({ entity, hops = 1, relationType, search, limit = 50, offset = 0, idempotencyKey } = {}) {
|
|
4093
|
+
const params = { hops, limit, offset };
|
|
4094
|
+
if (entity) params.entity = entity;
|
|
4095
|
+
if (relationType) params.relation_type = relationType;
|
|
4096
|
+
if (search) params.search = search;
|
|
4097
|
+
return this._t.request(this._base, "GET", "/api/v1/relationships", { params, idempotencyKey });
|
|
4098
|
+
}
|
|
4099
|
+
/** GET /api/v1/map.viewport — everything inside a bounding box (THE SCREEN): capped, id-ordered `pins`
|
|
4100
|
+
* + `counts_by_type` (counts are the TRUE totals for the whole bbox; pins are a sample). Params:
|
|
4101
|
+
* minLat/minLng/maxLat/maxLng (the bbox), entityType (deposit|infrastructure|company|project — default
|
|
4102
|
+
* all four), energy (default false), includeCountryCentroids (default false). AGENT KEYS ONLY; metered
|
|
4103
|
+
* against the CALLING agent's wallet (quote with billingQuote); pins do NOT count against your entity
|
|
4104
|
+
* cap. Same as the MCP `map_viewport` tool. Use this — the old /mapdata bulk surface is CLOSED. */
|
|
4105
|
+
mapViewport({
|
|
4106
|
+
minLat,
|
|
4107
|
+
minLng,
|
|
4108
|
+
maxLat,
|
|
4109
|
+
maxLng,
|
|
4110
|
+
entityType,
|
|
4111
|
+
energy = false,
|
|
4112
|
+
includeCountryCentroids = false,
|
|
4113
|
+
idempotencyKey
|
|
4114
|
+
} = {}) {
|
|
4115
|
+
const params = { energy, include_country_centroids: includeCountryCentroids };
|
|
4116
|
+
if (minLat != null) params.min_lat = minLat;
|
|
4117
|
+
if (minLng != null) params.min_lng = minLng;
|
|
4118
|
+
if (maxLat != null) params.max_lat = maxLat;
|
|
4119
|
+
if (maxLng != null) params.max_lng = maxLng;
|
|
4120
|
+
if (entityType != null) params.entity_type = entityType;
|
|
4121
|
+
return this._t.request(this._base, "GET", "/api/v1/map.viewport", { params, idempotencyKey });
|
|
4122
|
+
}
|
|
4123
|
+
/** GET /api/v1/look.at — a Sentinel-2 satellite STILL of a point (lat+lng) or an entity (entityType+id).
|
|
4124
|
+
* AGENT KEYS ONLY (a browser session or plain developer key is refused before any charge). Metered
|
|
4125
|
+
* against the CALLING agent's wallet — its own price line (~150 J; quote with
|
|
4126
|
+
* billingQuote("/api/v1/look.at")). On a hit returns { available: true, content_type: "image/jpeg",
|
|
4127
|
+
* image_jpeg: Uint8Array, provenance: { X-* headers — scene date, source, … } }; on a cloudy/missing
|
|
4128
|
+
* scene a { available: false, … } object (the charge is refunded server-side). Same as the MCP
|
|
4129
|
+
* `look_at` tool. */
|
|
4130
|
+
async lookAt({ lat, lng, entityType, id, idempotencyKey } = {}) {
|
|
4131
|
+
const params = {};
|
|
4132
|
+
if (lat != null) params.lat = lat;
|
|
4133
|
+
if (lng != null) params.lng = lng;
|
|
4134
|
+
if (entityType != null) params.entity_type = entityType;
|
|
4135
|
+
if (id != null) params.id = id;
|
|
4136
|
+
const r = await this._t.request(
|
|
4137
|
+
this._base,
|
|
4138
|
+
"GET",
|
|
4139
|
+
"/api/v1/look.at",
|
|
4140
|
+
{ params, idempotencyKey, accept: "image/jpeg, application/json", raw: true }
|
|
4141
|
+
);
|
|
4142
|
+
if (r && r._raw) {
|
|
4143
|
+
return { available: true, content_type: r.content_type, image_jpeg: r.content, provenance: r.provenance || {} };
|
|
4144
|
+
}
|
|
4145
|
+
return r;
|
|
4146
|
+
}
|
|
4147
|
+
/** YOUR OWN metered-read charge record — GET /api/v1/billing/attempts. Own wallet only (from your
|
|
4148
|
+
* credential, never a parameter). FREE. Each attempt shows reserved vs settled joules so you can verify
|
|
4149
|
+
* your bill without asking us (settle_dead_end = nothing moved — a 4xx/5xx or refused reservation;
|
|
4150
|
+
* settle_failed = delivered but unsettled). Parity with the MCP `billing_attempts` tool. */
|
|
4151
|
+
billingAttempts({ limit, offset } = {}) {
|
|
4152
|
+
const params = {};
|
|
4153
|
+
if (limit != null) params.limit = limit;
|
|
4154
|
+
if (offset != null) params.offset = offset;
|
|
4155
|
+
return this._t.request(this._base, "GET", "/api/v1/billing/attempts", { params });
|
|
4156
|
+
}
|
|
4157
|
+
// ── contributor-programme reads (P-DAY.105) ──────────────────────
|
|
4158
|
+
/** Your Bridge record (session): contribution units at your standing's weight, plus promoted work. */
|
|
4159
|
+
agentBridge() {
|
|
4160
|
+
return this._t.request(this._base, "GET", "/api/v1/agent/bridge", {});
|
|
4161
|
+
}
|
|
4162
|
+
/** Your seat record (session): kind, vesting clock, allotment counter. A recorded intent, not a
|
|
4163
|
+
* share; nothing owed until Execution, which is not promised. */
|
|
4164
|
+
agentSeat() {
|
|
4165
|
+
return this._t.request(this._base, "GET", "/api/v1/agent/seat", {});
|
|
4166
|
+
}
|
|
4167
|
+
// ── Contributor programme grant management (TEN-13; P-DAY.106) ────
|
|
4168
|
+
// SESSION-ONLY: build the Client with your signed-in greenlandai.ai session
|
|
4169
|
+
// (oauthToken); an X-API-Key is refused 403. The submit/read methods below use X-API-Key.
|
|
4170
|
+
/** Enable contribute on an identity you own. SESSION-ONLY — build the Client with your signed-in
|
|
4171
|
+
* greenlandai.ai session (oauthToken), NOT an API key (a key is refused 403). target 'agent' grants
|
|
4172
|
+
* one of your gqa_ agents (agentId required, the default+safest); 'self' grants your OWN gai_ key and
|
|
4173
|
+
* requires acknowledgeWidenedKey=true. identity: 3-40 char slug. The grant lives on the identity,
|
|
4174
|
+
* survives key regeneration, does not inherit. POST /api/v1/agent/contribute/enable. */
|
|
4175
|
+
contributeEnable({ target, identity, agentId = null, acknowledgeWidenedKey = false }) {
|
|
4176
|
+
const body = { target, identity, acknowledge_widened_key: acknowledgeWidenedKey };
|
|
4177
|
+
if (agentId != null) body.agent_id = agentId;
|
|
4178
|
+
return this._t.request(this._base, "POST", "/api/v1/agent/contribute/enable", { body });
|
|
4179
|
+
}
|
|
4180
|
+
/** Clear the contribute grant (contribute only; the key still works everywhere else). SESSION-ONLY.
|
|
4181
|
+
* POST /api/v1/agent/contribute/disable. */
|
|
4182
|
+
contributeDisable({ target, agentId = null }) {
|
|
4183
|
+
const body = { target };
|
|
4184
|
+
if (agentId != null) body.agent_id = agentId;
|
|
4185
|
+
return this._t.request(this._base, "POST", "/api/v1/agent/contribute/disable", { body });
|
|
4186
|
+
}
|
|
4187
|
+
/** Grant status for your key and your active agents (is contribute enabled, under which identity).
|
|
4188
|
+
* SESSION-ONLY. Never returns a key. GET /api/v1/agent/contribute. */
|
|
4189
|
+
contributeGrantStatus() {
|
|
4190
|
+
return this._t.request(this._base, "GET", "/api/v1/agent/contribute", {});
|
|
4191
|
+
}
|
|
4192
|
+
// ── Contributor door: submit + your own reads (X-API-Key) ─────────
|
|
4193
|
+
// Build the Client with the gai_ key of an ENABLED identity. No agent_id is ever
|
|
4194
|
+
// sent — the door derives your contributor identity from the key.
|
|
4195
|
+
/** Submit evidenced relationships. Auth: X-API-Key — build the Client with the gai_ key of an ENABLED
|
|
4196
|
+
* identity (contributeEnable first); the gqa_ agent ID is NOT sent, the door derives identity from
|
|
4197
|
+
* the key. Each relation MUST carry subject, relation, object, source_url (a real http(s) page) and
|
|
4198
|
+
* quote (verbatim, >= 15 chars — the judge refutes against it). entities proposes a new endpoint only
|
|
4199
|
+
* alongside a relation that references it. Nothing is written on submit; claims queue for the nightly
|
|
4200
|
+
* judge (21:15 UTC). results[].status: queued_for_judgement / bundled_with_proposed_entity · duplicate
|
|
4201
|
+
* / already_pending · unmapped_relation · unresolved_subject|object (suggestions) · self_loop /
|
|
4202
|
+
* source_excluded / invalid. The verdict — promoted, HELD or dismissed, with its reason — appears per
|
|
4203
|
+
* item via contributeSubmissions(); the receipt via contributeReceipts(); HELD is not a failure, not
|
|
4204
|
+
* counted until decided. Standing weights live at client.joulepai.programmeConfig() — not restated.
|
|
4205
|
+
* POST /api/v1/contribute/relations. */
|
|
4206
|
+
contributeSubmit(relations, { entities = null } = {}) {
|
|
4207
|
+
const body = { relations };
|
|
4208
|
+
if (entities != null) body.entities = entities;
|
|
4209
|
+
return this._t.request(this._base, "POST", "/api/v1/contribute/relations", { body });
|
|
4210
|
+
}
|
|
4211
|
+
/** Your OWN contributor standing (X-API-Key of an enabled identity): totals, acceptanceRate,
|
|
4212
|
+
* pending_review, refused_at_door, standing and the thresholds that apply after a floor of
|
|
4213
|
+
* submissions. GET /api/v1/contribute/status. */
|
|
4214
|
+
contributeStats() {
|
|
4215
|
+
return this._t.request(this._base, "GET", "/api/v1/contribute/status", {});
|
|
4216
|
+
}
|
|
4217
|
+
/** Your OWN per-item submission outcomes (X-API-Key): each item's outcome (pending_review / accepted /
|
|
4218
|
+
* rejected) with the judge's reason verbatim in review_note (a HELD item carries the reason).
|
|
4219
|
+
* GET /api/v1/contribute/submissions. */
|
|
4220
|
+
contributeSubmissions({ limit = 50, offset = 0 } = {}) {
|
|
4221
|
+
return this._t.request(this._base, "GET", "/api/v1/contribute/submissions", { params: { limit, offset } });
|
|
4222
|
+
}
|
|
4223
|
+
/** Your OWN append-only contribution receipts (X-API-Key) — proof of what you submitted, with the
|
|
4224
|
+
* canonical claim hash (claim_sha256). Own rows only. GET /api/v1/contribute/receipts. */
|
|
4225
|
+
contributeReceipts({ limit = 50, offset = 0 } = {}) {
|
|
4226
|
+
return this._t.request(this._base, "GET", "/api/v1/contribute/receipts", { params: { limit, offset } });
|
|
4227
|
+
}
|
|
4228
|
+
};
|
|
4229
|
+
|
|
3970
4230
|
// src/joulepai.js
|
|
3971
4231
|
var JOULEPAI_BASE = "https://joulepai.ai/api/v1";
|
|
3972
4232
|
var UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
@@ -4011,7 +4271,11 @@ var JoulepaiSubmodule = class {
|
|
|
4011
4271
|
transferStatus(transferId) {
|
|
4012
4272
|
return this._t.request(this._base, "GET", "/wallet/transfer/{tid}/status", { pathParams: { tid: transferId } });
|
|
4013
4273
|
}
|
|
4014
|
-
/**
|
|
4274
|
+
/** FIAT/CARD funding — POST /wallet/fund. method="stripe" returns a Stripe Checkout URL for a human to
|
|
4275
|
+
* complete (card; 3.5% markup; amountFiat 10-100). The backend also accepts method="usdc" (1% markup),
|
|
4276
|
+
* but the IN-BAND AGENT USDC rail is the deposit-address flow, NOT this endpoint: an agent funds by
|
|
4277
|
+
* depositing USDC to its own Base address — use fundingPrepare() for the address + live availability and
|
|
4278
|
+
* depositStatus() to track the credit. NOT retry-safe (G1 demotion — duplicate Stripe sessions). */
|
|
4015
4279
|
async fund(amountFiat, { method = "stripe" } = {}) {
|
|
4016
4280
|
return this._t.request(
|
|
4017
4281
|
this._base,
|
|
@@ -4021,6 +4285,9 @@ var JoulepaiSubmodule = class {
|
|
|
4021
4285
|
);
|
|
4022
4286
|
}
|
|
4023
4287
|
async balance() {
|
|
4288
|
+
if (this._t.isGreenlandaiAgentKey) {
|
|
4289
|
+
return (await this._t.request(GLDAI_BASE, "GET", "/api/v1/agent/me/balance", {})).balance_joules;
|
|
4290
|
+
}
|
|
4024
4291
|
return (await this._t.request(
|
|
4025
4292
|
this._base,
|
|
4026
4293
|
"GET",
|
|
@@ -4031,9 +4298,11 @@ var JoulepaiSubmodule = class {
|
|
|
4031
4298
|
/** Given a planned `cost` (e.g. a quote's joules_all_in from client.gldai.billingQuote), read a balance
|
|
4032
4299
|
* and return { needed, have, shortfall, can_afford } — the SDK twin of the MCP `joules_deficit` tool.
|
|
4033
4300
|
* Defaults to the authenticated wallet; pass `walletId` to check a specific wallet (parity with the MCP
|
|
4034
|
-
* joules_deficit(wallet_id, cost) signature).
|
|
4301
|
+
* joules_deficit(wallet_id, cost) signature). For a GreenlandAI agent key (gai_/gqa_) the balance is
|
|
4302
|
+
* always the agent's OWN (GreenlandAI's agent-self endpoint is own-wallet only), so `walletId` is
|
|
4303
|
+
* ignored for those keys. */
|
|
4035
4304
|
async deficit(cost, walletId = null) {
|
|
4036
|
-
const have = walletId != null ? (await this._t.request(this._base, "GET", "/wallet/balance/{wid}", { pathParams: { wid: walletId } })).balance : await this.balance();
|
|
4305
|
+
const have = walletId != null && !this._t.isGreenlandaiAgentKey ? (await this._t.request(this._base, "GET", "/wallet/balance/{wid}", { pathParams: { wid: walletId } })).balance : await this.balance();
|
|
4037
4306
|
const shortfall = Math.max(0, Number(cost) - Number(have));
|
|
4038
4307
|
return { needed: Number(cost), have: Number(have), shortfall, can_afford: shortfall === 0 };
|
|
4039
4308
|
}
|
|
@@ -4101,6 +4370,47 @@ var JoulepaiSubmodule = class {
|
|
|
4101
4370
|
fundingStatus(fundingEventId) {
|
|
4102
4371
|
return this._t.request(this._base, "GET", "/wallet/fund/{fid}", { pathParams: { fid: fundingEventId } });
|
|
4103
4372
|
}
|
|
4373
|
+
/** YOUR OWN USDC-on-Base deposit state — GET /wallet/deposit-status. Own wallet only (from your token,
|
|
4374
|
+
* never a parameter). Read-only, free. Returns { usdc_live, scanner_cursor_block, minimum_usdc,
|
|
4375
|
+
* deposits[], held_below_min_total_usdc, needed_to_credit_usdc, note }; each deposit carries { tx_hash,
|
|
4376
|
+
* block_number, usdc_amount, status, joules_credited, fee_taken, created_at, meaning }. A deposit whose
|
|
4377
|
+
* block_number is ABOVE scanner_cursor_block has not been reached yet (normal lag), not lost. 503 when
|
|
4378
|
+
* USDC-on-Base is not live. Parity with the MCP `deposit_status` tool. */
|
|
4379
|
+
depositStatus() {
|
|
4380
|
+
return this._t.request(this._base, "GET", "/wallet/deposit-status", {});
|
|
4381
|
+
}
|
|
4382
|
+
/** The in-band funding step for a joule shortfall — NEVER a URL to visit (operator lock). USDC on Base is
|
|
4383
|
+
* the live agent-fundable rail: deposit USDC to your own Base address (min 5 USDC — the authoritative
|
|
4384
|
+
* value is depositStatus().minimum_usdc), credited automatically when the scanner sees it (track with
|
|
4385
|
+
* depositStatus()). Card funding stays a human web flow. Availability is read LIVE (relays your
|
|
4386
|
+
* deposit-address) so it never reports stale state; it does not itself move money. Parity with the MCP
|
|
4387
|
+
* `funding_prepare` tool. Returns { needed, in_band_agent_funding_live, routes, note }. */
|
|
4388
|
+
async fundingPrepare(needed = 0) {
|
|
4389
|
+
let live = true, address = null;
|
|
4390
|
+
try {
|
|
4391
|
+
const addr = await this.depositAddress();
|
|
4392
|
+
address = addr && typeof addr === "object" ? addr.address ?? null : null;
|
|
4393
|
+
} catch (err) {
|
|
4394
|
+
if (err instanceof GreenlandAIError) {
|
|
4395
|
+
live = false;
|
|
4396
|
+
address = null;
|
|
4397
|
+
} else throw err;
|
|
4398
|
+
}
|
|
4399
|
+
return {
|
|
4400
|
+
needed: Number(needed),
|
|
4401
|
+
in_band_agent_funding_live: live,
|
|
4402
|
+
routes: {
|
|
4403
|
+
usdc_on_base: {
|
|
4404
|
+
status: live ? "live" : "not_live",
|
|
4405
|
+
deposit_address: address,
|
|
4406
|
+
minimum_usdc: 5,
|
|
4407
|
+
note: live ? "deposit USDC to this Base address; credited automatically within the scanner window; check with depositStatus()" : "no in-band USDC address for this credential right now \u2014 authenticate with your wallet credential, or fund with card meanwhile"
|
|
4408
|
+
},
|
|
4409
|
+
card_stripe: { status: "human_web_only", note: "not an agent/in-band path" }
|
|
4410
|
+
},
|
|
4411
|
+
note: live ? "USDC on Base is live \u2014 deposit to your Base address above (min 5 USDC), credited automatically; track it with depositStatus(). Do not follow a URL to fund." : "No in-band USDC address available for this credential; fund with card meanwhile. Do not follow a URL to fund."
|
|
4412
|
+
};
|
|
4413
|
+
}
|
|
4104
4414
|
resetCredentials(walletId, email) {
|
|
4105
4415
|
return this._t.request(
|
|
4106
4416
|
this._base,
|
|
@@ -4332,209 +4642,8 @@ var RareeaiSubmodule = class {
|
|
|
4332
4642
|
}
|
|
4333
4643
|
};
|
|
4334
4644
|
|
|
4335
|
-
// src/gldai.js
|
|
4336
|
-
var GLDAI_BASE = "https://greenlandai.ai";
|
|
4337
|
-
var GldaiSubmodule = class {
|
|
4338
|
-
constructor(transport, baseUrl = GLDAI_BASE) {
|
|
4339
|
-
this._t = transport;
|
|
4340
|
-
this._base = baseUrl;
|
|
4341
|
-
}
|
|
4342
|
-
companies({ idempotencyKey, ...params } = {}) {
|
|
4343
|
-
return this._t.request(this._base, "GET", "/api/v1/companies", { params, idempotencyKey });
|
|
4344
|
-
}
|
|
4345
|
-
company(companyId) {
|
|
4346
|
-
return this._t.request(this._base, "GET", "/api/v1/companies/{cid}", { pathParams: { cid: companyId } });
|
|
4347
|
-
}
|
|
4348
|
-
deposits({ idempotencyKey, ...params } = {}) {
|
|
4349
|
-
return this._t.request(this._base, "GET", "/api/v1/deposits", { params, idempotencyKey });
|
|
4350
|
-
}
|
|
4351
|
-
deposit(depositId) {
|
|
4352
|
-
return this._t.request(this._base, "GET", "/api/v1/deposits/{did}", { pathParams: { did: depositId } });
|
|
4353
|
-
}
|
|
4354
|
-
infrastructureList({ idempotencyKey, ...params } = {}) {
|
|
4355
|
-
return this._t.request(this._base, "GET", "/api/v1/infrastructure", { params, idempotencyKey });
|
|
4356
|
-
}
|
|
4357
|
-
infrastructure(infraId) {
|
|
4358
|
-
return this._t.request(this._base, "GET", "/api/v1/infrastructure/{iid}", { pathParams: { iid: infraId } });
|
|
4359
|
-
}
|
|
4360
|
-
/** GET /api/v1/query — the natural-language intelligence query, metered per call (Class C). WORKS FOR
|
|
4361
|
-
* JOULE-METERED AGENTS: they pay per query and are EXEMPT from the human NL access gates (the old
|
|
4362
|
-
* charged-then-403 for agents was fixed; api.py:1414 `_is_joule_agent` bypasses the email-verify /
|
|
4363
|
-
* door / entitlement checks, which apply to human accounts only). Humans need a verified ENYAL
|
|
4364
|
-
* identity + NL access ($10/level). Metered against the CALLING agent's wallet — quote with
|
|
4365
|
-
* billingQuote("/api/v1/query") first. */
|
|
4366
|
-
query(q, { idempotencyKey, ...params } = {}) {
|
|
4367
|
-
return this._t.request(this._base, "GET", "/api/v1/query", { params: { q, ...params }, idempotencyKey });
|
|
4368
|
-
}
|
|
4369
|
-
projects({ idempotencyKey, ...params } = {}) {
|
|
4370
|
-
return this._t.request(this._base, "GET", "/api/v1/projects", { params, idempotencyKey });
|
|
4371
|
-
}
|
|
4372
|
-
project(projectId) {
|
|
4373
|
-
return this._t.request(this._base, "GET", "/api/v1/projects/{pid}", { pathParams: { pid: projectId } });
|
|
4374
|
-
}
|
|
4375
|
-
mapdata({ idempotencyKey, ...params } = {}) {
|
|
4376
|
-
return this._t.request(this._base, "GET", "/api/v1/mapdata", { params, idempotencyKey });
|
|
4377
|
-
}
|
|
4378
|
-
// ── pricing + live map/graph read surface (2026-09-14; parity with the MCP tools) ──
|
|
4379
|
-
/** The exact per-caller price of a metered call BEFORE you make it — GET /api/v1/billing/quote. FREE
|
|
4380
|
-
* (no charge), needs only a credential (no verification). `path` = the API path the call would hit
|
|
4381
|
-
* (e.g. "/api/v1/relationships", "/api/v1/look.from", "/api/v1/nearby", "/api/v1/companies/{id}",
|
|
4382
|
-
* "/api/v1/mapdata"); `hops` = graph depth 1-20 for a relationships path. Priced at YOUR tier.
|
|
4383
|
-
* Returns { joules (base), rail_fee_joules, joules_all_in, pricing_tier, usd, … } — joules_all_in is
|
|
4384
|
-
* the TRUE debit (base + the 0.5% rail surcharge), so fund THAT, not the base. Same helper as the MCP
|
|
4385
|
-
* `billing_quote` tool. Metered reads debit the CALLING agent's OWN wallet (not the owner's); read the
|
|
4386
|
-
* balance with client.joulepai.balance() and check affordability with client.joulepai.deficit(). */
|
|
4387
|
-
billingQuote(path, hops = null) {
|
|
4388
|
-
const params = hops == null ? { path } : { path, hops };
|
|
4389
|
-
return this._t.request(this._base, "GET", "/api/v1/billing/quote", { params });
|
|
4390
|
-
}
|
|
4391
|
-
/** GET /api/v1/look.from — companies/infrastructure near a point (lat+lng) or anchored on one entity
|
|
4392
|
-
* (entityType+id). Metered against the CALLING agent's wallet (base + 0.5% rail; quote with
|
|
4393
|
-
* billingQuote). entityType behaves two ways (backend 2026-09-14): entityType ALONE (with lat/lng)
|
|
4394
|
-
* FILTERS the frame to that type; entityType + id ANCHORS the pose at that entity and keeps ALL types;
|
|
4395
|
-
* an unknown entityType is a 400 before any charge. Same as the MCP `look_from` tool. */
|
|
4396
|
-
lookFrom({
|
|
4397
|
-
lat,
|
|
4398
|
-
lng,
|
|
4399
|
-
entityType,
|
|
4400
|
-
id,
|
|
4401
|
-
radiusKm = 100,
|
|
4402
|
-
energy = false,
|
|
4403
|
-
includeCountryCentroids = false,
|
|
4404
|
-
idempotencyKey
|
|
4405
|
-
} = {}) {
|
|
4406
|
-
const params = { radius_km: radiusKm, energy, include_country_centroids: includeCountryCentroids };
|
|
4407
|
-
if (lat != null) params.lat = lat;
|
|
4408
|
-
if (lng != null) params.lng = lng;
|
|
4409
|
-
if (entityType != null) params.entity_type = entityType;
|
|
4410
|
-
if (id != null) params.id = id;
|
|
4411
|
-
return this._t.request(this._base, "GET", "/api/v1/look.from", { params, idempotencyKey });
|
|
4412
|
-
}
|
|
4413
|
-
/** GET /api/v1/nearby — entities near a location; here entityType IS a content filter. Metered against
|
|
4414
|
-
* the CALLING agent's wallet (quote with billingQuote). Same as the MCP `nearby` tool. */
|
|
4415
|
-
nearby({
|
|
4416
|
-
lat,
|
|
4417
|
-
lng,
|
|
4418
|
-
radiusKm = 100,
|
|
4419
|
-
entityType,
|
|
4420
|
-
limit = 20,
|
|
4421
|
-
includeCountryCentroids = false,
|
|
4422
|
-
idempotencyKey
|
|
4423
|
-
} = {}) {
|
|
4424
|
-
const params = { lat, lng, radius_km: radiusKm, limit, include_country_centroids: includeCountryCentroids };
|
|
4425
|
-
if (entityType != null) params.entity_type = entityType;
|
|
4426
|
-
return this._t.request(this._base, "GET", "/api/v1/nearby", { params, idempotencyKey });
|
|
4427
|
-
}
|
|
4428
|
-
/** GET /api/v1/relationships — labelled relationship hops (the MCP `hops` tool). `entity` is the START
|
|
4429
|
-
* NODE, matched as a case-insensitive SUBSTRING of an entity NAME (never an id: "3" matches any name
|
|
4430
|
-
* containing "3"), so pass a full, distinctive name. `hops` = depth 1-10. Metered per hop against the
|
|
4431
|
-
* CALLING agent's wallet (quote with billingQuote("/api/v1/relationships", n)). */
|
|
4432
|
-
relationships({ entity, hops = 1, relationType, search, limit = 50, offset = 0, idempotencyKey } = {}) {
|
|
4433
|
-
const params = { hops, limit, offset };
|
|
4434
|
-
if (entity) params.entity = entity;
|
|
4435
|
-
if (relationType) params.relation_type = relationType;
|
|
4436
|
-
if (search) params.search = search;
|
|
4437
|
-
return this._t.request(this._base, "GET", "/api/v1/relationships", { params, idempotencyKey });
|
|
4438
|
-
}
|
|
4439
|
-
/** GET /api/v1/map.viewport — everything inside a bounding box (THE SCREEN): capped, id-ordered `pins`
|
|
4440
|
-
* + `counts_by_type` (counts are the TRUE totals for the whole bbox; pins are a sample). Params:
|
|
4441
|
-
* minLat/minLng/maxLat/maxLng (the bbox), entityType (deposit|infrastructure|company|project — default
|
|
4442
|
-
* all four), energy (default false), includeCountryCentroids (default false). AGENT KEYS ONLY; metered
|
|
4443
|
-
* against the CALLING agent's wallet (quote with billingQuote); pins do NOT count against your entity
|
|
4444
|
-
* cap. Same as the MCP `map_viewport` tool. Use this — the old /mapdata bulk surface is CLOSED. */
|
|
4445
|
-
mapViewport({
|
|
4446
|
-
minLat,
|
|
4447
|
-
minLng,
|
|
4448
|
-
maxLat,
|
|
4449
|
-
maxLng,
|
|
4450
|
-
entityType,
|
|
4451
|
-
energy = false,
|
|
4452
|
-
includeCountryCentroids = false,
|
|
4453
|
-
idempotencyKey
|
|
4454
|
-
} = {}) {
|
|
4455
|
-
const params = { energy, include_country_centroids: includeCountryCentroids };
|
|
4456
|
-
if (minLat != null) params.min_lat = minLat;
|
|
4457
|
-
if (minLng != null) params.min_lng = minLng;
|
|
4458
|
-
if (maxLat != null) params.max_lat = maxLat;
|
|
4459
|
-
if (maxLng != null) params.max_lng = maxLng;
|
|
4460
|
-
if (entityType != null) params.entity_type = entityType;
|
|
4461
|
-
return this._t.request(this._base, "GET", "/api/v1/map.viewport", { params, idempotencyKey });
|
|
4462
|
-
}
|
|
4463
|
-
// ── contributor-programme reads (P-DAY.105) ──────────────────────
|
|
4464
|
-
/** Your Bridge record (session): contribution units at your standing's weight, plus promoted work. */
|
|
4465
|
-
agentBridge() {
|
|
4466
|
-
return this._t.request(this._base, "GET", "/api/v1/agent/bridge", {});
|
|
4467
|
-
}
|
|
4468
|
-
/** Your seat record (session): kind, vesting clock, allotment counter. A recorded intent, not a
|
|
4469
|
-
* share; nothing owed until Execution, which is not promised. */
|
|
4470
|
-
agentSeat() {
|
|
4471
|
-
return this._t.request(this._base, "GET", "/api/v1/agent/seat", {});
|
|
4472
|
-
}
|
|
4473
|
-
// ── Contributor programme grant management (TEN-13; P-DAY.106) ────
|
|
4474
|
-
// SESSION-ONLY: build the Client with your signed-in greenlandai.ai session
|
|
4475
|
-
// (oauthToken); an X-API-Key is refused 403. The submit/read methods below use X-API-Key.
|
|
4476
|
-
/** Enable contribute on an identity you own. SESSION-ONLY — build the Client with your signed-in
|
|
4477
|
-
* greenlandai.ai session (oauthToken), NOT an API key (a key is refused 403). target 'agent' grants
|
|
4478
|
-
* one of your gqa_ agents (agentId required, the default+safest); 'self' grants your OWN gai_ key and
|
|
4479
|
-
* requires acknowledgeWidenedKey=true. identity: 3-40 char slug. The grant lives on the identity,
|
|
4480
|
-
* survives key regeneration, does not inherit. POST /api/v1/agent/contribute/enable. */
|
|
4481
|
-
contributeEnable({ target, identity, agentId = null, acknowledgeWidenedKey = false }) {
|
|
4482
|
-
const body = { target, identity, acknowledge_widened_key: acknowledgeWidenedKey };
|
|
4483
|
-
if (agentId != null) body.agent_id = agentId;
|
|
4484
|
-
return this._t.request(this._base, "POST", "/api/v1/agent/contribute/enable", { body });
|
|
4485
|
-
}
|
|
4486
|
-
/** Clear the contribute grant (contribute only; the key still works everywhere else). SESSION-ONLY.
|
|
4487
|
-
* POST /api/v1/agent/contribute/disable. */
|
|
4488
|
-
contributeDisable({ target, agentId = null }) {
|
|
4489
|
-
const body = { target };
|
|
4490
|
-
if (agentId != null) body.agent_id = agentId;
|
|
4491
|
-
return this._t.request(this._base, "POST", "/api/v1/agent/contribute/disable", { body });
|
|
4492
|
-
}
|
|
4493
|
-
/** Grant status for your key and your active agents (is contribute enabled, under which identity).
|
|
4494
|
-
* SESSION-ONLY. Never returns a key. GET /api/v1/agent/contribute. */
|
|
4495
|
-
contributeGrantStatus() {
|
|
4496
|
-
return this._t.request(this._base, "GET", "/api/v1/agent/contribute", {});
|
|
4497
|
-
}
|
|
4498
|
-
// ── Contributor door: submit + your own reads (X-API-Key) ─────────
|
|
4499
|
-
// Build the Client with the gai_ key of an ENABLED identity. No agent_id is ever
|
|
4500
|
-
// sent — the door derives your contributor identity from the key.
|
|
4501
|
-
/** Submit evidenced relationships. Auth: X-API-Key — build the Client with the gai_ key of an ENABLED
|
|
4502
|
-
* identity (contributeEnable first); the gqa_ agent ID is NOT sent, the door derives identity from
|
|
4503
|
-
* the key. Each relation MUST carry subject, relation, object, source_url (a real http(s) page) and
|
|
4504
|
-
* quote (verbatim, >= 15 chars — the judge refutes against it). entities proposes a new endpoint only
|
|
4505
|
-
* alongside a relation that references it. Nothing is written on submit; claims queue for the nightly
|
|
4506
|
-
* judge (21:15 UTC). results[].status: queued_for_judgement / bundled_with_proposed_entity · duplicate
|
|
4507
|
-
* / already_pending · unmapped_relation · unresolved_subject|object (suggestions) · self_loop /
|
|
4508
|
-
* source_excluded / invalid. The verdict — promoted, HELD or dismissed, with its reason — appears per
|
|
4509
|
-
* item via contributeSubmissions(); the receipt via contributeReceipts(); HELD is not a failure, not
|
|
4510
|
-
* counted until decided. Standing weights live at client.joulepai.programmeConfig() — not restated.
|
|
4511
|
-
* POST /api/v1/contribute/relations. */
|
|
4512
|
-
contributeSubmit(relations, { entities = null } = {}) {
|
|
4513
|
-
const body = { relations };
|
|
4514
|
-
if (entities != null) body.entities = entities;
|
|
4515
|
-
return this._t.request(this._base, "POST", "/api/v1/contribute/relations", { body });
|
|
4516
|
-
}
|
|
4517
|
-
/** Your OWN contributor standing (X-API-Key of an enabled identity): totals, acceptanceRate,
|
|
4518
|
-
* pending_review, refused_at_door, standing and the thresholds that apply after a floor of
|
|
4519
|
-
* submissions. GET /api/v1/contribute/status. */
|
|
4520
|
-
contributeStats() {
|
|
4521
|
-
return this._t.request(this._base, "GET", "/api/v1/contribute/status", {});
|
|
4522
|
-
}
|
|
4523
|
-
/** Your OWN per-item submission outcomes (X-API-Key): each item's outcome (pending_review / accepted /
|
|
4524
|
-
* rejected) with the judge's reason verbatim in review_note (a HELD item carries the reason).
|
|
4525
|
-
* GET /api/v1/contribute/submissions. */
|
|
4526
|
-
contributeSubmissions({ limit = 50, offset = 0 } = {}) {
|
|
4527
|
-
return this._t.request(this._base, "GET", "/api/v1/contribute/submissions", { params: { limit, offset } });
|
|
4528
|
-
}
|
|
4529
|
-
/** Your OWN append-only contribution receipts (X-API-Key) — proof of what you submitted, with the
|
|
4530
|
-
* canonical claim hash (claim_sha256). Own rows only. GET /api/v1/contribute/receipts. */
|
|
4531
|
-
contributeReceipts({ limit = 50, offset = 0 } = {}) {
|
|
4532
|
-
return this._t.request(this._base, "GET", "/api/v1/contribute/receipts", { params: { limit, offset } });
|
|
4533
|
-
}
|
|
4534
|
-
};
|
|
4535
|
-
|
|
4536
4645
|
// index.js
|
|
4537
|
-
var VERSION = "0.5.
|
|
4646
|
+
var VERSION = "0.5.3";
|
|
4538
4647
|
var Client = class {
|
|
4539
4648
|
/**
|
|
4540
4649
|
* @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.
|
|
19
|
+
export const VERSION = "0.5.3";
|
|
20
20
|
|
|
21
21
|
export class Client {
|
|
22
22
|
/**
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@greenlandai/sdk",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.4",
|
|
4
4
|
"description": "Unified SDK for the GreenlandAI ecosystem (ENYAL, JoulePAI, RAREEAI, GreenlandAI)",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
|
-
"homepage": "https://
|
|
6
|
+
"homepage": "https://greenlandai.ai",
|
|
7
7
|
"publishConfig": {
|
|
8
8
|
"access": "public"
|
|
9
9
|
},
|
package/src/core/idempotency.js
CHANGED
|
@@ -44,6 +44,7 @@ export const IDEMPOTENCY_MAP = {
|
|
|
44
44
|
"GET /api/v1/nearby": { field: "X-Idempotency-Key", placement: "header", tier: ENFORCED },
|
|
45
45
|
"GET /api/v1/relationships": { field: "X-Idempotency-Key", placement: "header", tier: ENFORCED },
|
|
46
46
|
"GET /api/v1/map.viewport": { field: "X-Idempotency-Key", placement: "header", tier: ENFORCED },
|
|
47
|
+
"GET /api/v1/look.at": { field: "X-Idempotency-Key", placement: "header", tier: ENFORCED },
|
|
47
48
|
// (cf) ENYAL metered GET — joins Class C header class (server reads X-Idempotency-Key per the Option-B switch)
|
|
48
49
|
"GET /api/v1/search": { field: "X-Idempotency-Key", placement: "header", tier: ENFORCED },
|
|
49
50
|
// Class D — transfer-class
|
package/src/core/transport.js
CHANGED
|
@@ -50,10 +50,19 @@ export class Transport {
|
|
|
50
50
|
this._fetch = fetchImpl || fetch;
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
+
/** True when the credential is a GreenlandAI agent API key (gai_/gqa_). Used ONLY to choose which
|
|
54
|
+
* backend serves this key's OWN wallet balance (GreenlandAI's free agent-self endpoint vs JoulePAI) —
|
|
55
|
+
* NOT for auth-header selection, which stays parameter-based (§2). A gai_/gqa_ key has no JoulePAI
|
|
56
|
+
* wallet row; its balance lives at GET /api/v1/agent/me/balance (free). */
|
|
57
|
+
get isGreenlandaiAgentKey() {
|
|
58
|
+
return this._isApiKey && (this._credential.startsWith("gai_") || this._credential.startsWith("gqa_"));
|
|
59
|
+
}
|
|
60
|
+
|
|
53
61
|
async request(baseUrl, method, pathTemplate,
|
|
54
62
|
{ pathParams = {}, body = null, params = null,
|
|
55
63
|
idempotencyKey = null, retry = true,
|
|
56
|
-
maxRetries = DEFAULT_MAX_RETRIES
|
|
64
|
+
maxRetries = DEFAULT_MAX_RETRIES,
|
|
65
|
+
accept = null, raw = false } = {}) {
|
|
57
66
|
// Auth header by parameter (X-API-Key for apiKey incl. eyl_/gai_; Bearer for an OAuth JWT).
|
|
58
67
|
// See docs/canonical/security-policy.md (X-API-Key > Bearer > cookie).
|
|
59
68
|
let headers = this._isApiKey
|
|
@@ -76,7 +85,7 @@ export class Transport {
|
|
|
76
85
|
const t0 = Date.now();
|
|
77
86
|
for (;;) {
|
|
78
87
|
try {
|
|
79
|
-
const result = await this._once(method, url, headers, body);
|
|
88
|
+
const result = await this._once(method, url, headers, body, { accept, raw });
|
|
80
89
|
this._count("sdk.requests"); this._hist("sdk.request.duration", (Date.now() - t0) / 1000);
|
|
81
90
|
if (result && result.duplicate === true) {
|
|
82
91
|
this._count("sdk.duplicates");
|
|
@@ -102,7 +111,7 @@ export class Transport {
|
|
|
102
111
|
}
|
|
103
112
|
}
|
|
104
113
|
|
|
105
|
-
async _once(method, url, headers, body) {
|
|
114
|
+
async _once(method, url, headers, body, { accept = null, raw = false } = {}) {
|
|
106
115
|
const redacted = { ...headers };
|
|
107
116
|
if ("Authorization" in redacted) redacted.Authorization = "[REDACTED]";
|
|
108
117
|
if ("X-API-Key" in redacted) redacted["X-API-Key"] = "[REDACTED]";
|
|
@@ -110,6 +119,7 @@ export class Transport {
|
|
|
110
119
|
let resp;
|
|
111
120
|
try {
|
|
112
121
|
const opts = { method, headers: { ...headers } };
|
|
122
|
+
if (accept) opts.headers["Accept"] = accept;
|
|
113
123
|
if (body != null) {
|
|
114
124
|
opts.headers["Content-Type"] = "application/json";
|
|
115
125
|
opts.body = JSON.stringify(body);
|
|
@@ -128,6 +138,17 @@ export class Transport {
|
|
|
128
138
|
if (typeof detail === "object") detail = JSON.stringify(detail);
|
|
129
139
|
throw errorForStatus(resp.status, String(detail), requestId, retryAfter);
|
|
130
140
|
}
|
|
141
|
+
if (raw) {
|
|
142
|
+
// Binary-capable path (look.at: image/jpeg body, or a 200 JSON {available:false}).
|
|
143
|
+
const ct = resp.headers?.get ? (resp.headers.get("content-type") || "") : "";
|
|
144
|
+
if (ct.startsWith("application/json")) return resp.json();
|
|
145
|
+
const buf = await resp.arrayBuffer();
|
|
146
|
+
const provenance = {};
|
|
147
|
+
if (resp.headers?.forEach) resp.headers.forEach((v, k) => {
|
|
148
|
+
if (k.toLowerCase().startsWith("x-")) provenance[k] = v;
|
|
149
|
+
});
|
|
150
|
+
return { _raw: true, content_type: ct, content: new Uint8Array(buf), provenance };
|
|
151
|
+
}
|
|
131
152
|
if (resp.status === 204) return null;
|
|
132
153
|
return resp.json();
|
|
133
154
|
}
|
package/src/gldai.js
CHANGED
|
@@ -48,6 +48,9 @@ export class GldaiSubmodule {
|
|
|
48
48
|
project(projectId) {
|
|
49
49
|
return this._t.request(this._base, "GET", "/api/v1/projects/{pid}", { pathParams: { pid: projectId } });
|
|
50
50
|
}
|
|
51
|
+
/** CLOSED — do NOT call. GET /api/v1/mapdata (the bulk map-layers surface) is closed to all callers and
|
|
52
|
+
* returns an error. Use mapViewport() for map reads. Kept only so the method still resolves for older
|
|
53
|
+
* callers. Matches the MCP `mapdata` tool (also marked CLOSED). */
|
|
51
54
|
mapdata({ idempotencyKey, ...params } = {}) {
|
|
52
55
|
return this._t.request(this._base, "GET", "/api/v1/mapdata", { params, idempotencyKey });
|
|
53
56
|
}
|
|
@@ -56,7 +59,8 @@ export class GldaiSubmodule {
|
|
|
56
59
|
/** The exact per-caller price of a metered call BEFORE you make it — GET /api/v1/billing/quote. FREE
|
|
57
60
|
* (no charge), needs only a credential (no verification). `path` = the API path the call would hit
|
|
58
61
|
* (e.g. "/api/v1/relationships", "/api/v1/look.from", "/api/v1/nearby", "/api/v1/companies/{id}",
|
|
59
|
-
* "/api/v1/mapdata"); `hops` = graph depth 1-
|
|
62
|
+
* "/api/v1/mapdata"); `hops` = graph depth 1-10 (your tier caps it — Pioneer/FC 3, TEN/Pro 5,
|
|
63
|
+
* Enterprise 10) for a relationships path. Priced at YOUR tier.
|
|
60
64
|
* Returns { joules (base), rail_fee_joules, joules_all_in, pricing_tier, usd, … } — joules_all_in is
|
|
61
65
|
* the TRUE debit (base + the 0.5% rail surcharge), so fund THAT, not the base. Same helper as the MCP
|
|
62
66
|
* `billing_quote` tool. Metered reads debit the CALLING agent's OWN wallet (not the owner's); read the
|
|
@@ -114,6 +118,36 @@ export class GldaiSubmodule {
|
|
|
114
118
|
if (entityType != null) params.entity_type = entityType;
|
|
115
119
|
return this._t.request(this._base, "GET", "/api/v1/map.viewport", { params, idempotencyKey });
|
|
116
120
|
}
|
|
121
|
+
/** GET /api/v1/look.at — a Sentinel-2 satellite STILL of a point (lat+lng) or an entity (entityType+id).
|
|
122
|
+
* AGENT KEYS ONLY (a browser session or plain developer key is refused before any charge). Metered
|
|
123
|
+
* against the CALLING agent's wallet — its own price line (~150 J; quote with
|
|
124
|
+
* billingQuote("/api/v1/look.at")). On a hit returns { available: true, content_type: "image/jpeg",
|
|
125
|
+
* image_jpeg: Uint8Array, provenance: { X-* headers — scene date, source, … } }; on a cloudy/missing
|
|
126
|
+
* scene a { available: false, … } object (the charge is refunded server-side). Same as the MCP
|
|
127
|
+
* `look_at` tool. */
|
|
128
|
+
async lookAt({ lat, lng, entityType, id, idempotencyKey } = {}) {
|
|
129
|
+
const params = {};
|
|
130
|
+
if (lat != null) params.lat = lat;
|
|
131
|
+
if (lng != null) params.lng = lng;
|
|
132
|
+
if (entityType != null) params.entity_type = entityType;
|
|
133
|
+
if (id != null) params.id = id;
|
|
134
|
+
const r = await this._t.request(this._base, "GET", "/api/v1/look.at",
|
|
135
|
+
{ params, idempotencyKey, accept: "image/jpeg, application/json", raw: true });
|
|
136
|
+
if (r && r._raw) {
|
|
137
|
+
return { available: true, content_type: r.content_type, image_jpeg: r.content, provenance: r.provenance || {} };
|
|
138
|
+
}
|
|
139
|
+
return r; // a 200 JSON { available: false, … } passes straight through
|
|
140
|
+
}
|
|
141
|
+
/** YOUR OWN metered-read charge record — GET /api/v1/billing/attempts. Own wallet only (from your
|
|
142
|
+
* credential, never a parameter). FREE. Each attempt shows reserved vs settled joules so you can verify
|
|
143
|
+
* your bill without asking us (settle_dead_end = nothing moved — a 4xx/5xx or refused reservation;
|
|
144
|
+
* settle_failed = delivered but unsettled). Parity with the MCP `billing_attempts` tool. */
|
|
145
|
+
billingAttempts({ limit, offset } = {}) {
|
|
146
|
+
const params = {};
|
|
147
|
+
if (limit != null) params.limit = limit;
|
|
148
|
+
if (offset != null) params.offset = offset;
|
|
149
|
+
return this._t.request(this._base, "GET", "/api/v1/billing/attempts", { params });
|
|
150
|
+
}
|
|
117
151
|
|
|
118
152
|
// ── contributor-programme reads (P-DAY.105) ──────────────────────
|
|
119
153
|
/** Your Bridge record (session): contribution units at your standing's weight, plus promoted work. */
|
package/src/joulepai.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
/** client.joulepai — 17-method Wallet absorb (design §4.2; AUDIT.6).
|
|
2
2
|
* Source-of-record: local joulepai-sdk-js/index.js (never published).
|
|
3
3
|
* Transfer-class now carries Class-D keys via dispatch (the local SDK sent none). */
|
|
4
|
+
import { GLDAI_BASE } from "./gldai.js"; // reuse the single greenlandai.ai base for the agent-self balance route
|
|
5
|
+
import { GreenlandAIError } from "./core/errors.js";
|
|
6
|
+
|
|
4
7
|
export const JOULEPAI_BASE = "https://joulepai.ai/api/v1";
|
|
5
8
|
|
|
6
9
|
const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
@@ -44,13 +47,20 @@ export class JoulepaiSubmodule {
|
|
|
44
47
|
return this._t.request(this._base, "GET", "/wallet/transfer/{tid}/status", { pathParams: { tid: transferId } });
|
|
45
48
|
}
|
|
46
49
|
|
|
47
|
-
/**
|
|
50
|
+
/** FIAT/CARD funding — POST /wallet/fund. method="stripe" returns a Stripe Checkout URL for a human to
|
|
51
|
+
* complete (card; 3.5% markup; amountFiat 10-100). The backend also accepts method="usdc" (1% markup),
|
|
52
|
+
* but the IN-BAND AGENT USDC rail is the deposit-address flow, NOT this endpoint: an agent funds by
|
|
53
|
+
* depositing USDC to its own Base address — use fundingPrepare() for the address + live availability and
|
|
54
|
+
* depositStatus() to track the credit. NOT retry-safe (G1 demotion — duplicate Stripe sessions). */
|
|
48
55
|
async fund(amountFiat, { method = "stripe" } = {}) {
|
|
49
56
|
return this._t.request(this._base, "POST", "/wallet/fund",
|
|
50
57
|
{ body: { wallet_id: await this._ensureId(), amount_fiat: amountFiat, method } });
|
|
51
58
|
}
|
|
52
59
|
|
|
53
60
|
async balance() {
|
|
61
|
+
if (this._t.isGreenlandaiAgentKey) {
|
|
62
|
+
return (await this._t.request(GLDAI_BASE, "GET", "/api/v1/agent/me/balance", {})).balance_joules;
|
|
63
|
+
}
|
|
54
64
|
return (await this._t.request(this._base, "GET", "/wallet/balance/{wid}",
|
|
55
65
|
{ pathParams: { wid: await this._ensureId() } })).balance;
|
|
56
66
|
}
|
|
@@ -58,9 +68,11 @@ export class JoulepaiSubmodule {
|
|
|
58
68
|
/** Given a planned `cost` (e.g. a quote's joules_all_in from client.gldai.billingQuote), read a balance
|
|
59
69
|
* and return { needed, have, shortfall, can_afford } — the SDK twin of the MCP `joules_deficit` tool.
|
|
60
70
|
* Defaults to the authenticated wallet; pass `walletId` to check a specific wallet (parity with the MCP
|
|
61
|
-
* joules_deficit(wallet_id, cost) signature).
|
|
71
|
+
* joules_deficit(wallet_id, cost) signature). For a GreenlandAI agent key (gai_/gqa_) the balance is
|
|
72
|
+
* always the agent's OWN (GreenlandAI's agent-self endpoint is own-wallet only), so `walletId` is
|
|
73
|
+
* ignored for those keys. */
|
|
62
74
|
async deficit(cost, walletId = null) {
|
|
63
|
-
const have = walletId != null
|
|
75
|
+
const have = (walletId != null && !this._t.isGreenlandaiAgentKey)
|
|
64
76
|
? (await this._t.request(this._base, "GET", "/wallet/balance/{wid}", { pathParams: { wid: walletId } })).balance
|
|
65
77
|
: await this.balance();
|
|
66
78
|
const shortfall = Math.max(0, Number(cost) - Number(have));
|
|
@@ -113,6 +125,49 @@ export class JoulepaiSubmodule {
|
|
|
113
125
|
return this._t.request(this._base, "GET", "/wallet/fund/{fid}", { pathParams: { fid: fundingEventId } });
|
|
114
126
|
}
|
|
115
127
|
|
|
128
|
+
/** YOUR OWN USDC-on-Base deposit state — GET /wallet/deposit-status. Own wallet only (from your token,
|
|
129
|
+
* never a parameter). Read-only, free. Returns { usdc_live, scanner_cursor_block, minimum_usdc,
|
|
130
|
+
* deposits[], held_below_min_total_usdc, needed_to_credit_usdc, note }; each deposit carries { tx_hash,
|
|
131
|
+
* block_number, usdc_amount, status, joules_credited, fee_taken, created_at, meaning }. A deposit whose
|
|
132
|
+
* block_number is ABOVE scanner_cursor_block has not been reached yet (normal lag), not lost. 503 when
|
|
133
|
+
* USDC-on-Base is not live. Parity with the MCP `deposit_status` tool. */
|
|
134
|
+
depositStatus() { return this._t.request(this._base, "GET", "/wallet/deposit-status", {}); }
|
|
135
|
+
|
|
136
|
+
/** The in-band funding step for a joule shortfall — NEVER a URL to visit (operator lock). USDC on Base is
|
|
137
|
+
* the live agent-fundable rail: deposit USDC to your own Base address (min 5 USDC — the authoritative
|
|
138
|
+
* value is depositStatus().minimum_usdc), credited automatically when the scanner sees it (track with
|
|
139
|
+
* depositStatus()). Card funding stays a human web flow. Availability is read LIVE (relays your
|
|
140
|
+
* deposit-address) so it never reports stale state; it does not itself move money. Parity with the MCP
|
|
141
|
+
* `funding_prepare` tool. Returns { needed, in_band_agent_funding_live, routes, note }. */
|
|
142
|
+
async fundingPrepare(needed = 0) {
|
|
143
|
+
let live = true, address = null;
|
|
144
|
+
try {
|
|
145
|
+
const addr = await this.depositAddress();
|
|
146
|
+
address = addr && typeof addr === "object" ? addr.address ?? null : null;
|
|
147
|
+
} catch (err) {
|
|
148
|
+
if (err instanceof GreenlandAIError) { live = false; address = null; }
|
|
149
|
+
else throw err;
|
|
150
|
+
}
|
|
151
|
+
return {
|
|
152
|
+
needed: Number(needed),
|
|
153
|
+
in_band_agent_funding_live: live,
|
|
154
|
+
routes: {
|
|
155
|
+
usdc_on_base: {
|
|
156
|
+
status: live ? "live" : "not_live",
|
|
157
|
+
deposit_address: address,
|
|
158
|
+
minimum_usdc: 5,
|
|
159
|
+
note: live
|
|
160
|
+
? "deposit USDC to this Base address; credited automatically within the scanner window; check with depositStatus()"
|
|
161
|
+
: "no in-band USDC address for this credential right now — authenticate with your wallet credential, or fund with card meanwhile",
|
|
162
|
+
},
|
|
163
|
+
card_stripe: { status: "human_web_only", note: "not an agent/in-band path" },
|
|
164
|
+
},
|
|
165
|
+
note: live
|
|
166
|
+
? "USDC on Base is live — deposit to your Base address above (min 5 USDC), credited automatically; track it with depositStatus(). Do not follow a URL to fund."
|
|
167
|
+
: "No in-band USDC address available for this credential; fund with card meanwhile. Do not follow a URL to fund.",
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
|
|
116
171
|
resetCredentials(walletId, email) {
|
|
117
172
|
return this._t.request(this._base, "POST", "/wallet/reset-credentials",
|
|
118
173
|
{ body: { wallet_id: walletId, email } });
|