@greenlandai/sdk 0.5.0 → 0.5.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/dist/index.cjs +79 -1
- package/index.js +1 -1
- package/package.json +1 -1
- package/src/core/idempotency.js +4 -0
- package/src/gldai.js +61 -1
- package/src/joulepai.js +9 -0
package/dist/index.cjs
CHANGED
|
@@ -112,6 +112,10 @@ var IDEMPOTENCY_MAP = {
|
|
|
112
112
|
"GET /api/v1/query": { field: "X-Idempotency-Key", placement: "header", tier: ENFORCED },
|
|
113
113
|
"GET /api/v1/projects": { field: "X-Idempotency-Key", placement: "header", tier: ENFORCED },
|
|
114
114
|
"GET /api/v1/mapdata": { field: "X-Idempotency-Key", placement: "header", tier: ENFORCED },
|
|
115
|
+
// metered map/graph read surface (2026-09-14 SDK wrappers — parity with the MCP tools)
|
|
116
|
+
"GET /api/v1/look.from": { field: "X-Idempotency-Key", placement: "header", tier: ENFORCED },
|
|
117
|
+
"GET /api/v1/nearby": { field: "X-Idempotency-Key", placement: "header", tier: ENFORCED },
|
|
118
|
+
"GET /api/v1/relationships": { field: "X-Idempotency-Key", placement: "header", tier: ENFORCED },
|
|
115
119
|
// (cf) ENYAL metered GET — joins Class C header class (server reads X-Idempotency-Key per the Option-B switch)
|
|
116
120
|
"GET /api/v1/search": { field: "X-Idempotency-Key", placement: "header", tier: ENFORCED },
|
|
117
121
|
// Class D — transfer-class
|
|
@@ -4023,6 +4027,14 @@ var JoulepaiSubmodule = class {
|
|
|
4023
4027
|
{ pathParams: { wid: await this._ensureId() } }
|
|
4024
4028
|
)).balance;
|
|
4025
4029
|
}
|
|
4030
|
+
/** Given a planned `cost` (e.g. a quote's joules_all_in from client.gldai.billingQuote), read your OWN
|
|
4031
|
+
* balance and return { needed, have, shortfall, can_afford } — the SDK twin of the MCP `joules_deficit`
|
|
4032
|
+
* tool. Reads the authenticated wallet; no walletId needed. */
|
|
4033
|
+
async deficit(cost) {
|
|
4034
|
+
const have = await this.balance();
|
|
4035
|
+
const shortfall = Math.max(0, Number(cost) - Number(have));
|
|
4036
|
+
return { needed: Number(cost), have: Number(have), shortfall, can_afford: shortfall === 0 };
|
|
4037
|
+
}
|
|
4026
4038
|
async info() {
|
|
4027
4039
|
return this._t.request(
|
|
4028
4040
|
this._base,
|
|
@@ -4343,6 +4355,12 @@ var GldaiSubmodule = class {
|
|
|
4343
4355
|
infrastructure(infraId) {
|
|
4344
4356
|
return this._t.request(this._base, "GET", "/api/v1/infrastructure/{iid}", { pathParams: { iid: infraId } });
|
|
4345
4357
|
}
|
|
4358
|
+
/** GET /api/v1/query — the natural-language intelligence query, metered per call (Class C). WORKS FOR
|
|
4359
|
+
* JOULE-METERED AGENTS: they pay per query and are EXEMPT from the human NL access gates (the old
|
|
4360
|
+
* charged-then-403 for agents was fixed; api.py:1414 `_is_joule_agent` bypasses the email-verify /
|
|
4361
|
+
* door / entitlement checks, which apply to human accounts only). Humans need a verified ENYAL
|
|
4362
|
+
* identity + NL access ($10/level). Metered against the CALLING agent's wallet — quote with
|
|
4363
|
+
* billingQuote("/api/v1/query") first. */
|
|
4346
4364
|
query(q, { idempotencyKey, ...params } = {}) {
|
|
4347
4365
|
return this._t.request(this._base, "GET", "/api/v1/query", { params: { q, ...params }, idempotencyKey });
|
|
4348
4366
|
}
|
|
@@ -4355,6 +4373,66 @@ var GldaiSubmodule = class {
|
|
|
4355
4373
|
mapdata({ idempotencyKey, ...params } = {}) {
|
|
4356
4374
|
return this._t.request(this._base, "GET", "/api/v1/mapdata", { params, idempotencyKey });
|
|
4357
4375
|
}
|
|
4376
|
+
// ── pricing + live map/graph read surface (2026-09-14; parity with the MCP tools) ──
|
|
4377
|
+
/** The exact per-caller price of a metered call BEFORE you make it — GET /api/v1/billing/quote. FREE
|
|
4378
|
+
* (no charge), needs only a credential (no verification). `path` = the API path the call would hit
|
|
4379
|
+
* (e.g. "/api/v1/relationships", "/api/v1/look.from", "/api/v1/nearby", "/api/v1/companies/{id}",
|
|
4380
|
+
* "/api/v1/mapdata"); `hops` = graph depth 1-20 for a relationships path. Priced at YOUR tier.
|
|
4381
|
+
* Returns { joules (base), rail_fee_joules, joules_all_in, pricing_tier, usd, … } — joules_all_in is
|
|
4382
|
+
* the TRUE debit (base + the 0.5% rail surcharge), so fund THAT, not the base. Same helper as the MCP
|
|
4383
|
+
* `billing_quote` tool. Metered reads debit the CALLING agent's OWN wallet (not the owner's); read the
|
|
4384
|
+
* balance with client.joulepai.balance() and check affordability with client.joulepai.deficit(). */
|
|
4385
|
+
billingQuote(path, hops = null) {
|
|
4386
|
+
const params = hops == null ? { path } : { path, hops };
|
|
4387
|
+
return this._t.request(this._base, "GET", "/api/v1/billing/quote", { params });
|
|
4388
|
+
}
|
|
4389
|
+
/** GET /api/v1/look.from — companies/infrastructure near a point (lat+lng) or anchored on one entity
|
|
4390
|
+
* (entityType+id). Metered against the CALLING agent's wallet (base + 0.5% rail; quote with
|
|
4391
|
+
* billingQuote). NOTE: entityType here is a POSE-ANCHOR used with id, NOT a content filter — for
|
|
4392
|
+
* type-filtered results use nearby(). Same as the MCP `look_from` tool. */
|
|
4393
|
+
lookFrom({
|
|
4394
|
+
lat,
|
|
4395
|
+
lng,
|
|
4396
|
+
entityType,
|
|
4397
|
+
id,
|
|
4398
|
+
radiusKm = 100,
|
|
4399
|
+
energy = false,
|
|
4400
|
+
includeCountryCentroids = false,
|
|
4401
|
+
idempotencyKey
|
|
4402
|
+
} = {}) {
|
|
4403
|
+
const params = { radius_km: radiusKm, energy, include_country_centroids: includeCountryCentroids };
|
|
4404
|
+
if (lat != null) params.lat = lat;
|
|
4405
|
+
if (lng != null) params.lng = lng;
|
|
4406
|
+
if (entityType != null) params.entity_type = entityType;
|
|
4407
|
+
if (id != null) params.id = id;
|
|
4408
|
+
return this._t.request(this._base, "GET", "/api/v1/look.from", { params, idempotencyKey });
|
|
4409
|
+
}
|
|
4410
|
+
/** GET /api/v1/nearby — entities near a location; here entityType IS a content filter. Metered against
|
|
4411
|
+
* the CALLING agent's wallet (quote with billingQuote). Same as the MCP `nearby` tool. */
|
|
4412
|
+
nearby({
|
|
4413
|
+
lat,
|
|
4414
|
+
lng,
|
|
4415
|
+
radiusKm = 100,
|
|
4416
|
+
entityType,
|
|
4417
|
+
limit = 20,
|
|
4418
|
+
includeCountryCentroids = false,
|
|
4419
|
+
idempotencyKey
|
|
4420
|
+
} = {}) {
|
|
4421
|
+
const params = { lat, lng, radius_km: radiusKm, limit, include_country_centroids: includeCountryCentroids };
|
|
4422
|
+
if (entityType != null) params.entity_type = entityType;
|
|
4423
|
+
return this._t.request(this._base, "GET", "/api/v1/nearby", { params, idempotencyKey });
|
|
4424
|
+
}
|
|
4425
|
+
/** GET /api/v1/relationships — labelled relationship hops (the MCP `hops` tool). `entity` is the START
|
|
4426
|
+
* NODE, matched as a case-insensitive SUBSTRING of an entity NAME (never an id: "3" matches any name
|
|
4427
|
+
* containing "3"), so pass a full, distinctive name. `hops` = depth 1-10. Metered per hop against the
|
|
4428
|
+
* CALLING agent's wallet (quote with billingQuote("/api/v1/relationships", n)). */
|
|
4429
|
+
relationships({ entity, hops = 1, relationType, search, limit = 50, offset = 0, idempotencyKey } = {}) {
|
|
4430
|
+
const params = { hops, limit, offset };
|
|
4431
|
+
if (entity) params.entity = entity;
|
|
4432
|
+
if (relationType) params.relation_type = relationType;
|
|
4433
|
+
if (search) params.search = search;
|
|
4434
|
+
return this._t.request(this._base, "GET", "/api/v1/relationships", { params, idempotencyKey });
|
|
4435
|
+
}
|
|
4358
4436
|
// ── contributor-programme reads (P-DAY.105) ──────────────────────
|
|
4359
4437
|
/** Your Bridge record (session): contribution units at your standing's weight, plus promoted work. */
|
|
4360
4438
|
agentBridge() {
|
|
@@ -4429,7 +4507,7 @@ var GldaiSubmodule = class {
|
|
|
4429
4507
|
};
|
|
4430
4508
|
|
|
4431
4509
|
// index.js
|
|
4432
|
-
var VERSION = "0.5.
|
|
4510
|
+
var VERSION = "0.5.1";
|
|
4433
4511
|
var Client = class {
|
|
4434
4512
|
/**
|
|
4435
4513
|
* @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.1";
|
|
20
20
|
|
|
21
21
|
export class Client {
|
|
22
22
|
/**
|
package/package.json
CHANGED
package/src/core/idempotency.js
CHANGED
|
@@ -39,6 +39,10 @@ export const IDEMPOTENCY_MAP = {
|
|
|
39
39
|
"GET /api/v1/query": { field: "X-Idempotency-Key", placement: "header", tier: ENFORCED },
|
|
40
40
|
"GET /api/v1/projects": { field: "X-Idempotency-Key", placement: "header", tier: ENFORCED },
|
|
41
41
|
"GET /api/v1/mapdata": { field: "X-Idempotency-Key", placement: "header", tier: ENFORCED },
|
|
42
|
+
// metered map/graph read surface (2026-09-14 SDK wrappers — parity with the MCP tools)
|
|
43
|
+
"GET /api/v1/look.from": { field: "X-Idempotency-Key", placement: "header", tier: ENFORCED },
|
|
44
|
+
"GET /api/v1/nearby": { field: "X-Idempotency-Key", placement: "header", tier: ENFORCED },
|
|
45
|
+
"GET /api/v1/relationships": { field: "X-Idempotency-Key", placement: "header", tier: ENFORCED },
|
|
42
46
|
// (cf) ENYAL metered GET — joins Class C header class (server reads X-Idempotency-Key per the Option-B switch)
|
|
43
47
|
"GET /api/v1/search": { field: "X-Idempotency-Key", placement: "header", tier: ENFORCED },
|
|
44
48
|
// Class D — transfer-class
|
package/src/gldai.js
CHANGED
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
/** client.gldai — intelligence query surface (design §4.4; enumerated at BUILD
|
|
2
2
|
* 2026-06-10 from api.py route registrations :692-:1221, read-only). Class C
|
|
3
|
-
* metering middleware-side (rate_limiter.py:256 -> joule_metering).
|
|
3
|
+
* metering middleware-side (rate_limiter.py:256 -> joule_metering).
|
|
4
|
+
* Pricing + affordability (helpers, not a pointer — 2026-09-14): a metered call debits
|
|
5
|
+
* the CALLING agent's OWN wallet (not the owner's). Price any call BEFORE you make it
|
|
6
|
+
* with billingQuote(path, hops) — free, returns joules / rail_fee_joules / joules_all_in
|
|
7
|
+
* (the TRUE debit = base + the 0.5% rail surcharge). Read the balance with
|
|
8
|
+
* client.joulepai.balance() and check affordability with client.joulepai.deficit(cost).
|
|
9
|
+
* The live map/graph read surface is wrapped here too — lookFrom, nearby, relationships
|
|
10
|
+
* (the MCP `hops` tool) — alongside companies/deposits/infrastructure/projects/mapdata/
|
|
11
|
+
* query; helper names match the MCP tools. Nothing on this surface is MCP-only. */
|
|
4
12
|
export const GLDAI_BASE = "https://greenlandai.ai";
|
|
5
13
|
|
|
6
14
|
export class GldaiSubmodule {
|
|
@@ -25,6 +33,12 @@ export class GldaiSubmodule {
|
|
|
25
33
|
infrastructure(infraId) {
|
|
26
34
|
return this._t.request(this._base, "GET", "/api/v1/infrastructure/{iid}", { pathParams: { iid: infraId } });
|
|
27
35
|
}
|
|
36
|
+
/** GET /api/v1/query — the natural-language intelligence query, metered per call (Class C). WORKS FOR
|
|
37
|
+
* JOULE-METERED AGENTS: they pay per query and are EXEMPT from the human NL access gates (the old
|
|
38
|
+
* charged-then-403 for agents was fixed; api.py:1414 `_is_joule_agent` bypasses the email-verify /
|
|
39
|
+
* door / entitlement checks, which apply to human accounts only). Humans need a verified ENYAL
|
|
40
|
+
* identity + NL access ($10/level). Metered against the CALLING agent's wallet — quote with
|
|
41
|
+
* billingQuote("/api/v1/query") first. */
|
|
28
42
|
query(q, { idempotencyKey, ...params } = {}) {
|
|
29
43
|
return this._t.request(this._base, "GET", "/api/v1/query", { params: { q, ...params }, idempotencyKey });
|
|
30
44
|
}
|
|
@@ -38,6 +52,52 @@ export class GldaiSubmodule {
|
|
|
38
52
|
return this._t.request(this._base, "GET", "/api/v1/mapdata", { params, idempotencyKey });
|
|
39
53
|
}
|
|
40
54
|
|
|
55
|
+
// ── pricing + live map/graph read surface (2026-09-14; parity with the MCP tools) ──
|
|
56
|
+
/** The exact per-caller price of a metered call BEFORE you make it — GET /api/v1/billing/quote. FREE
|
|
57
|
+
* (no charge), needs only a credential (no verification). `path` = the API path the call would hit
|
|
58
|
+
* (e.g. "/api/v1/relationships", "/api/v1/look.from", "/api/v1/nearby", "/api/v1/companies/{id}",
|
|
59
|
+
* "/api/v1/mapdata"); `hops` = graph depth 1-20 for a relationships path. Priced at YOUR tier.
|
|
60
|
+
* Returns { joules (base), rail_fee_joules, joules_all_in, pricing_tier, usd, … } — joules_all_in is
|
|
61
|
+
* the TRUE debit (base + the 0.5% rail surcharge), so fund THAT, not the base. Same helper as the MCP
|
|
62
|
+
* `billing_quote` tool. Metered reads debit the CALLING agent's OWN wallet (not the owner's); read the
|
|
63
|
+
* balance with client.joulepai.balance() and check affordability with client.joulepai.deficit(). */
|
|
64
|
+
billingQuote(path, hops = null) {
|
|
65
|
+
const params = hops == null ? { path } : { path, hops };
|
|
66
|
+
return this._t.request(this._base, "GET", "/api/v1/billing/quote", { params });
|
|
67
|
+
}
|
|
68
|
+
/** GET /api/v1/look.from — companies/infrastructure near a point (lat+lng) or anchored on one entity
|
|
69
|
+
* (entityType+id). Metered against the CALLING agent's wallet (base + 0.5% rail; quote with
|
|
70
|
+
* billingQuote). NOTE: entityType here is a POSE-ANCHOR used with id, NOT a content filter — for
|
|
71
|
+
* type-filtered results use nearby(). Same as the MCP `look_from` tool. */
|
|
72
|
+
lookFrom({ lat, lng, entityType, id, radiusKm = 100, energy = false,
|
|
73
|
+
includeCountryCentroids = false, idempotencyKey } = {}) {
|
|
74
|
+
const params = { radius_km: radiusKm, energy, include_country_centroids: includeCountryCentroids };
|
|
75
|
+
if (lat != null) params.lat = lat;
|
|
76
|
+
if (lng != null) params.lng = lng;
|
|
77
|
+
if (entityType != null) params.entity_type = entityType;
|
|
78
|
+
if (id != null) params.id = id;
|
|
79
|
+
return this._t.request(this._base, "GET", "/api/v1/look.from", { params, idempotencyKey });
|
|
80
|
+
}
|
|
81
|
+
/** GET /api/v1/nearby — entities near a location; here entityType IS a content filter. Metered against
|
|
82
|
+
* the CALLING agent's wallet (quote with billingQuote). Same as the MCP `nearby` tool. */
|
|
83
|
+
nearby({ lat, lng, radiusKm = 100, entityType, limit = 20,
|
|
84
|
+
includeCountryCentroids = false, idempotencyKey } = {}) {
|
|
85
|
+
const params = { lat, lng, radius_km: radiusKm, limit, include_country_centroids: includeCountryCentroids };
|
|
86
|
+
if (entityType != null) params.entity_type = entityType;
|
|
87
|
+
return this._t.request(this._base, "GET", "/api/v1/nearby", { params, idempotencyKey });
|
|
88
|
+
}
|
|
89
|
+
/** GET /api/v1/relationships — labelled relationship hops (the MCP `hops` tool). `entity` is the START
|
|
90
|
+
* NODE, matched as a case-insensitive SUBSTRING of an entity NAME (never an id: "3" matches any name
|
|
91
|
+
* containing "3"), so pass a full, distinctive name. `hops` = depth 1-10. Metered per hop against the
|
|
92
|
+
* CALLING agent's wallet (quote with billingQuote("/api/v1/relationships", n)). */
|
|
93
|
+
relationships({ entity, hops = 1, relationType, search, limit = 50, offset = 0, idempotencyKey } = {}) {
|
|
94
|
+
const params = { hops, limit, offset };
|
|
95
|
+
if (entity) params.entity = entity;
|
|
96
|
+
if (relationType) params.relation_type = relationType;
|
|
97
|
+
if (search) params.search = search;
|
|
98
|
+
return this._t.request(this._base, "GET", "/api/v1/relationships", { params, idempotencyKey });
|
|
99
|
+
}
|
|
100
|
+
|
|
41
101
|
// ── contributor-programme reads (P-DAY.105) ──────────────────────
|
|
42
102
|
/** Your Bridge record (session): contribution units at your standing's weight, plus promoted work. */
|
|
43
103
|
agentBridge() {
|
package/src/joulepai.js
CHANGED
|
@@ -55,6 +55,15 @@ export class JoulepaiSubmodule {
|
|
|
55
55
|
{ pathParams: { wid: await this._ensureId() } })).balance;
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
+
/** Given a planned `cost` (e.g. a quote's joules_all_in from client.gldai.billingQuote), read your OWN
|
|
59
|
+
* balance and return { needed, have, shortfall, can_afford } — the SDK twin of the MCP `joules_deficit`
|
|
60
|
+
* tool. Reads the authenticated wallet; no walletId needed. */
|
|
61
|
+
async deficit(cost) {
|
|
62
|
+
const have = await this.balance();
|
|
63
|
+
const shortfall = Math.max(0, Number(cost) - Number(have));
|
|
64
|
+
return { needed: Number(cost), have: Number(have), shortfall, can_afford: shortfall === 0 };
|
|
65
|
+
}
|
|
66
|
+
|
|
58
67
|
async info() {
|
|
59
68
|
return this._t.request(this._base, "GET", "/wallet/balance/{wid}",
|
|
60
69
|
{ pathParams: { wid: await this._ensureId() } });
|