@greenlandai/sdk 0.5.2 → 0.5.3
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 +216 -204
- package/index.js +1 -1
- package/package.json +1 -1
- package/src/core/transport.js +8 -0
- package/src/joulepai.js +9 -2
package/dist/index.cjs
CHANGED
|
@@ -205,6 +205,13 @@ var Transport = class {
|
|
|
205
205
|
this.metrics = metrics || null;
|
|
206
206
|
this._fetch = fetchImpl || fetch;
|
|
207
207
|
}
|
|
208
|
+
/** True when the credential is a GreenlandAI agent API key (gai_/gqa_). Used ONLY to choose which
|
|
209
|
+
* backend serves this key's OWN wallet balance (GreenlandAI's free agent-self endpoint vs JoulePAI) —
|
|
210
|
+
* NOT for auth-header selection, which stays parameter-based (§2). A gai_/gqa_ key has no JoulePAI
|
|
211
|
+
* wallet row; its balance lives at GET /api/v1/agent/me/balance (free). */
|
|
212
|
+
get isGreenlandaiAgentKey() {
|
|
213
|
+
return this._isApiKey && (this._credential.startsWith("gai_") || this._credential.startsWith("gqa_"));
|
|
214
|
+
}
|
|
208
215
|
async request(baseUrl, method, pathTemplate, {
|
|
209
216
|
pathParams = {},
|
|
210
217
|
body = null,
|
|
@@ -3967,6 +3974,207 @@ var EnyalSubmodule = class {
|
|
|
3967
3974
|
}
|
|
3968
3975
|
};
|
|
3969
3976
|
|
|
3977
|
+
// src/gldai.js
|
|
3978
|
+
var GLDAI_BASE = "https://greenlandai.ai";
|
|
3979
|
+
var GldaiSubmodule = class {
|
|
3980
|
+
constructor(transport, baseUrl = GLDAI_BASE) {
|
|
3981
|
+
this._t = transport;
|
|
3982
|
+
this._base = baseUrl;
|
|
3983
|
+
}
|
|
3984
|
+
companies({ idempotencyKey, ...params } = {}) {
|
|
3985
|
+
return this._t.request(this._base, "GET", "/api/v1/companies", { params, idempotencyKey });
|
|
3986
|
+
}
|
|
3987
|
+
company(companyId) {
|
|
3988
|
+
return this._t.request(this._base, "GET", "/api/v1/companies/{cid}", { pathParams: { cid: companyId } });
|
|
3989
|
+
}
|
|
3990
|
+
deposits({ idempotencyKey, ...params } = {}) {
|
|
3991
|
+
return this._t.request(this._base, "GET", "/api/v1/deposits", { params, idempotencyKey });
|
|
3992
|
+
}
|
|
3993
|
+
deposit(depositId) {
|
|
3994
|
+
return this._t.request(this._base, "GET", "/api/v1/deposits/{did}", { pathParams: { did: depositId } });
|
|
3995
|
+
}
|
|
3996
|
+
infrastructureList({ idempotencyKey, ...params } = {}) {
|
|
3997
|
+
return this._t.request(this._base, "GET", "/api/v1/infrastructure", { params, idempotencyKey });
|
|
3998
|
+
}
|
|
3999
|
+
infrastructure(infraId) {
|
|
4000
|
+
return this._t.request(this._base, "GET", "/api/v1/infrastructure/{iid}", { pathParams: { iid: infraId } });
|
|
4001
|
+
}
|
|
4002
|
+
/** GET /api/v1/query — the natural-language intelligence query, metered per call (Class C). WORKS FOR
|
|
4003
|
+
* JOULE-METERED AGENTS: they pay per query and are EXEMPT from the human NL access gates (the old
|
|
4004
|
+
* charged-then-403 for agents was fixed; api.py:1414 `_is_joule_agent` bypasses the email-verify /
|
|
4005
|
+
* door / entitlement checks, which apply to human accounts only). Humans need a verified ENYAL
|
|
4006
|
+
* identity + NL access ($10/level). Metered against the CALLING agent's wallet — quote with
|
|
4007
|
+
* billingQuote("/api/v1/query") first. */
|
|
4008
|
+
query(q, { idempotencyKey, ...params } = {}) {
|
|
4009
|
+
return this._t.request(this._base, "GET", "/api/v1/query", { params: { q, ...params }, idempotencyKey });
|
|
4010
|
+
}
|
|
4011
|
+
projects({ idempotencyKey, ...params } = {}) {
|
|
4012
|
+
return this._t.request(this._base, "GET", "/api/v1/projects", { params, idempotencyKey });
|
|
4013
|
+
}
|
|
4014
|
+
project(projectId) {
|
|
4015
|
+
return this._t.request(this._base, "GET", "/api/v1/projects/{pid}", { pathParams: { pid: projectId } });
|
|
4016
|
+
}
|
|
4017
|
+
mapdata({ idempotencyKey, ...params } = {}) {
|
|
4018
|
+
return this._t.request(this._base, "GET", "/api/v1/mapdata", { params, idempotencyKey });
|
|
4019
|
+
}
|
|
4020
|
+
// ── pricing + live map/graph read surface (2026-09-14; parity with the MCP tools) ──
|
|
4021
|
+
/** The exact per-caller price of a metered call BEFORE you make it — GET /api/v1/billing/quote. FREE
|
|
4022
|
+
* (no charge), needs only a credential (no verification). `path` = the API path the call would hit
|
|
4023
|
+
* (e.g. "/api/v1/relationships", "/api/v1/look.from", "/api/v1/nearby", "/api/v1/companies/{id}",
|
|
4024
|
+
* "/api/v1/mapdata"); `hops` = graph depth 1-20 for a relationships path. Priced at YOUR tier.
|
|
4025
|
+
* Returns { joules (base), rail_fee_joules, joules_all_in, pricing_tier, usd, … } — joules_all_in is
|
|
4026
|
+
* the TRUE debit (base + the 0.5% rail surcharge), so fund THAT, not the base. Same helper as the MCP
|
|
4027
|
+
* `billing_quote` tool. Metered reads debit the CALLING agent's OWN wallet (not the owner's); read the
|
|
4028
|
+
* balance with client.joulepai.balance() and check affordability with client.joulepai.deficit(). */
|
|
4029
|
+
billingQuote(path, hops = null) {
|
|
4030
|
+
const params = hops == null ? { path } : { path, hops };
|
|
4031
|
+
return this._t.request(this._base, "GET", "/api/v1/billing/quote", { params });
|
|
4032
|
+
}
|
|
4033
|
+
/** GET /api/v1/look.from — companies/infrastructure near a point (lat+lng) or anchored on one entity
|
|
4034
|
+
* (entityType+id). Metered against the CALLING agent's wallet (base + 0.5% rail; quote with
|
|
4035
|
+
* billingQuote). entityType behaves two ways (backend 2026-09-14): entityType ALONE (with lat/lng)
|
|
4036
|
+
* FILTERS the frame to that type; entityType + id ANCHORS the pose at that entity and keeps ALL types;
|
|
4037
|
+
* an unknown entityType is a 400 before any charge. Same as the MCP `look_from` tool. */
|
|
4038
|
+
lookFrom({
|
|
4039
|
+
lat,
|
|
4040
|
+
lng,
|
|
4041
|
+
entityType,
|
|
4042
|
+
id,
|
|
4043
|
+
radiusKm = 100,
|
|
4044
|
+
energy = false,
|
|
4045
|
+
includeCountryCentroids = false,
|
|
4046
|
+
idempotencyKey
|
|
4047
|
+
} = {}) {
|
|
4048
|
+
const params = { radius_km: radiusKm, energy, include_country_centroids: includeCountryCentroids };
|
|
4049
|
+
if (lat != null) params.lat = lat;
|
|
4050
|
+
if (lng != null) params.lng = lng;
|
|
4051
|
+
if (entityType != null) params.entity_type = entityType;
|
|
4052
|
+
if (id != null) params.id = id;
|
|
4053
|
+
return this._t.request(this._base, "GET", "/api/v1/look.from", { params, idempotencyKey });
|
|
4054
|
+
}
|
|
4055
|
+
/** GET /api/v1/nearby — entities near a location; here entityType IS a content filter. Metered against
|
|
4056
|
+
* the CALLING agent's wallet (quote with billingQuote). Same as the MCP `nearby` tool. */
|
|
4057
|
+
nearby({
|
|
4058
|
+
lat,
|
|
4059
|
+
lng,
|
|
4060
|
+
radiusKm = 100,
|
|
4061
|
+
entityType,
|
|
4062
|
+
limit = 20,
|
|
4063
|
+
includeCountryCentroids = false,
|
|
4064
|
+
idempotencyKey
|
|
4065
|
+
} = {}) {
|
|
4066
|
+
const params = { lat, lng, radius_km: radiusKm, limit, include_country_centroids: includeCountryCentroids };
|
|
4067
|
+
if (entityType != null) params.entity_type = entityType;
|
|
4068
|
+
return this._t.request(this._base, "GET", "/api/v1/nearby", { params, idempotencyKey });
|
|
4069
|
+
}
|
|
4070
|
+
/** GET /api/v1/relationships — labelled relationship hops (the MCP `hops` tool). `entity` is the START
|
|
4071
|
+
* NODE, matched as a case-insensitive SUBSTRING of an entity NAME (never an id: "3" matches any name
|
|
4072
|
+
* containing "3"), so pass a full, distinctive name. `hops` = depth 1-10. Metered per hop against the
|
|
4073
|
+
* CALLING agent's wallet (quote with billingQuote("/api/v1/relationships", n)). */
|
|
4074
|
+
relationships({ entity, hops = 1, relationType, search, limit = 50, offset = 0, idempotencyKey } = {}) {
|
|
4075
|
+
const params = { hops, limit, offset };
|
|
4076
|
+
if (entity) params.entity = entity;
|
|
4077
|
+
if (relationType) params.relation_type = relationType;
|
|
4078
|
+
if (search) params.search = search;
|
|
4079
|
+
return this._t.request(this._base, "GET", "/api/v1/relationships", { params, idempotencyKey });
|
|
4080
|
+
}
|
|
4081
|
+
/** GET /api/v1/map.viewport — everything inside a bounding box (THE SCREEN): capped, id-ordered `pins`
|
|
4082
|
+
* + `counts_by_type` (counts are the TRUE totals for the whole bbox; pins are a sample). Params:
|
|
4083
|
+
* minLat/minLng/maxLat/maxLng (the bbox), entityType (deposit|infrastructure|company|project — default
|
|
4084
|
+
* all four), energy (default false), includeCountryCentroids (default false). AGENT KEYS ONLY; metered
|
|
4085
|
+
* against the CALLING agent's wallet (quote with billingQuote); pins do NOT count against your entity
|
|
4086
|
+
* cap. Same as the MCP `map_viewport` tool. Use this — the old /mapdata bulk surface is CLOSED. */
|
|
4087
|
+
mapViewport({
|
|
4088
|
+
minLat,
|
|
4089
|
+
minLng,
|
|
4090
|
+
maxLat,
|
|
4091
|
+
maxLng,
|
|
4092
|
+
entityType,
|
|
4093
|
+
energy = false,
|
|
4094
|
+
includeCountryCentroids = false,
|
|
4095
|
+
idempotencyKey
|
|
4096
|
+
} = {}) {
|
|
4097
|
+
const params = { energy, include_country_centroids: includeCountryCentroids };
|
|
4098
|
+
if (minLat != null) params.min_lat = minLat;
|
|
4099
|
+
if (minLng != null) params.min_lng = minLng;
|
|
4100
|
+
if (maxLat != null) params.max_lat = maxLat;
|
|
4101
|
+
if (maxLng != null) params.max_lng = maxLng;
|
|
4102
|
+
if (entityType != null) params.entity_type = entityType;
|
|
4103
|
+
return this._t.request(this._base, "GET", "/api/v1/map.viewport", { params, idempotencyKey });
|
|
4104
|
+
}
|
|
4105
|
+
// ── contributor-programme reads (P-DAY.105) ──────────────────────
|
|
4106
|
+
/** Your Bridge record (session): contribution units at your standing's weight, plus promoted work. */
|
|
4107
|
+
agentBridge() {
|
|
4108
|
+
return this._t.request(this._base, "GET", "/api/v1/agent/bridge", {});
|
|
4109
|
+
}
|
|
4110
|
+
/** Your seat record (session): kind, vesting clock, allotment counter. A recorded intent, not a
|
|
4111
|
+
* share; nothing owed until Execution, which is not promised. */
|
|
4112
|
+
agentSeat() {
|
|
4113
|
+
return this._t.request(this._base, "GET", "/api/v1/agent/seat", {});
|
|
4114
|
+
}
|
|
4115
|
+
// ── Contributor programme grant management (TEN-13; P-DAY.106) ────
|
|
4116
|
+
// SESSION-ONLY: build the Client with your signed-in greenlandai.ai session
|
|
4117
|
+
// (oauthToken); an X-API-Key is refused 403. The submit/read methods below use X-API-Key.
|
|
4118
|
+
/** Enable contribute on an identity you own. SESSION-ONLY — build the Client with your signed-in
|
|
4119
|
+
* greenlandai.ai session (oauthToken), NOT an API key (a key is refused 403). target 'agent' grants
|
|
4120
|
+
* one of your gqa_ agents (agentId required, the default+safest); 'self' grants your OWN gai_ key and
|
|
4121
|
+
* requires acknowledgeWidenedKey=true. identity: 3-40 char slug. The grant lives on the identity,
|
|
4122
|
+
* survives key regeneration, does not inherit. POST /api/v1/agent/contribute/enable. */
|
|
4123
|
+
contributeEnable({ target, identity, agentId = null, acknowledgeWidenedKey = false }) {
|
|
4124
|
+
const body = { target, identity, acknowledge_widened_key: acknowledgeWidenedKey };
|
|
4125
|
+
if (agentId != null) body.agent_id = agentId;
|
|
4126
|
+
return this._t.request(this._base, "POST", "/api/v1/agent/contribute/enable", { body });
|
|
4127
|
+
}
|
|
4128
|
+
/** Clear the contribute grant (contribute only; the key still works everywhere else). SESSION-ONLY.
|
|
4129
|
+
* POST /api/v1/agent/contribute/disable. */
|
|
4130
|
+
contributeDisable({ target, agentId = null }) {
|
|
4131
|
+
const body = { target };
|
|
4132
|
+
if (agentId != null) body.agent_id = agentId;
|
|
4133
|
+
return this._t.request(this._base, "POST", "/api/v1/agent/contribute/disable", { body });
|
|
4134
|
+
}
|
|
4135
|
+
/** Grant status for your key and your active agents (is contribute enabled, under which identity).
|
|
4136
|
+
* SESSION-ONLY. Never returns a key. GET /api/v1/agent/contribute. */
|
|
4137
|
+
contributeGrantStatus() {
|
|
4138
|
+
return this._t.request(this._base, "GET", "/api/v1/agent/contribute", {});
|
|
4139
|
+
}
|
|
4140
|
+
// ── Contributor door: submit + your own reads (X-API-Key) ─────────
|
|
4141
|
+
// Build the Client with the gai_ key of an ENABLED identity. No agent_id is ever
|
|
4142
|
+
// sent — the door derives your contributor identity from the key.
|
|
4143
|
+
/** Submit evidenced relationships. Auth: X-API-Key — build the Client with the gai_ key of an ENABLED
|
|
4144
|
+
* identity (contributeEnable first); the gqa_ agent ID is NOT sent, the door derives identity from
|
|
4145
|
+
* the key. Each relation MUST carry subject, relation, object, source_url (a real http(s) page) and
|
|
4146
|
+
* quote (verbatim, >= 15 chars — the judge refutes against it). entities proposes a new endpoint only
|
|
4147
|
+
* alongside a relation that references it. Nothing is written on submit; claims queue for the nightly
|
|
4148
|
+
* judge (21:15 UTC). results[].status: queued_for_judgement / bundled_with_proposed_entity · duplicate
|
|
4149
|
+
* / already_pending · unmapped_relation · unresolved_subject|object (suggestions) · self_loop /
|
|
4150
|
+
* source_excluded / invalid. The verdict — promoted, HELD or dismissed, with its reason — appears per
|
|
4151
|
+
* item via contributeSubmissions(); the receipt via contributeReceipts(); HELD is not a failure, not
|
|
4152
|
+
* counted until decided. Standing weights live at client.joulepai.programmeConfig() — not restated.
|
|
4153
|
+
* POST /api/v1/contribute/relations. */
|
|
4154
|
+
contributeSubmit(relations, { entities = null } = {}) {
|
|
4155
|
+
const body = { relations };
|
|
4156
|
+
if (entities != null) body.entities = entities;
|
|
4157
|
+
return this._t.request(this._base, "POST", "/api/v1/contribute/relations", { body });
|
|
4158
|
+
}
|
|
4159
|
+
/** Your OWN contributor standing (X-API-Key of an enabled identity): totals, acceptanceRate,
|
|
4160
|
+
* pending_review, refused_at_door, standing and the thresholds that apply after a floor of
|
|
4161
|
+
* submissions. GET /api/v1/contribute/status. */
|
|
4162
|
+
contributeStats() {
|
|
4163
|
+
return this._t.request(this._base, "GET", "/api/v1/contribute/status", {});
|
|
4164
|
+
}
|
|
4165
|
+
/** Your OWN per-item submission outcomes (X-API-Key): each item's outcome (pending_review / accepted /
|
|
4166
|
+
* rejected) with the judge's reason verbatim in review_note (a HELD item carries the reason).
|
|
4167
|
+
* GET /api/v1/contribute/submissions. */
|
|
4168
|
+
contributeSubmissions({ limit = 50, offset = 0 } = {}) {
|
|
4169
|
+
return this._t.request(this._base, "GET", "/api/v1/contribute/submissions", { params: { limit, offset } });
|
|
4170
|
+
}
|
|
4171
|
+
/** Your OWN append-only contribution receipts (X-API-Key) — proof of what you submitted, with the
|
|
4172
|
+
* canonical claim hash (claim_sha256). Own rows only. GET /api/v1/contribute/receipts. */
|
|
4173
|
+
contributeReceipts({ limit = 50, offset = 0 } = {}) {
|
|
4174
|
+
return this._t.request(this._base, "GET", "/api/v1/contribute/receipts", { params: { limit, offset } });
|
|
4175
|
+
}
|
|
4176
|
+
};
|
|
4177
|
+
|
|
3970
4178
|
// src/joulepai.js
|
|
3971
4179
|
var JOULEPAI_BASE = "https://joulepai.ai/api/v1";
|
|
3972
4180
|
var UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
@@ -4021,6 +4229,9 @@ var JoulepaiSubmodule = class {
|
|
|
4021
4229
|
);
|
|
4022
4230
|
}
|
|
4023
4231
|
async balance() {
|
|
4232
|
+
if (this._t.isGreenlandaiAgentKey) {
|
|
4233
|
+
return (await this._t.request(GLDAI_BASE, "GET", "/api/v1/agent/me/balance", {})).balance_joules;
|
|
4234
|
+
}
|
|
4024
4235
|
return (await this._t.request(
|
|
4025
4236
|
this._base,
|
|
4026
4237
|
"GET",
|
|
@@ -4031,9 +4242,11 @@ var JoulepaiSubmodule = class {
|
|
|
4031
4242
|
/** Given a planned `cost` (e.g. a quote's joules_all_in from client.gldai.billingQuote), read a balance
|
|
4032
4243
|
* and return { needed, have, shortfall, can_afford } — the SDK twin of the MCP `joules_deficit` tool.
|
|
4033
4244
|
* Defaults to the authenticated wallet; pass `walletId` to check a specific wallet (parity with the MCP
|
|
4034
|
-
* joules_deficit(wallet_id, cost) signature).
|
|
4245
|
+
* joules_deficit(wallet_id, cost) signature). For a GreenlandAI agent key (gai_/gqa_) the balance is
|
|
4246
|
+
* always the agent's OWN (GreenlandAI's agent-self endpoint is own-wallet only), so `walletId` is
|
|
4247
|
+
* ignored for those keys. */
|
|
4035
4248
|
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();
|
|
4249
|
+
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
4250
|
const shortfall = Math.max(0, Number(cost) - Number(have));
|
|
4038
4251
|
return { needed: Number(cost), have: Number(have), shortfall, can_afford: shortfall === 0 };
|
|
4039
4252
|
}
|
|
@@ -4332,209 +4545,8 @@ var RareeaiSubmodule = class {
|
|
|
4332
4545
|
}
|
|
4333
4546
|
};
|
|
4334
4547
|
|
|
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
4548
|
// index.js
|
|
4537
|
-
var VERSION = "0.5.
|
|
4549
|
+
var VERSION = "0.5.3";
|
|
4538
4550
|
var Client = class {
|
|
4539
4551
|
/**
|
|
4540
4552
|
* @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
package/src/core/transport.js
CHANGED
|
@@ -50,6 +50,14 @@ 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,
|
package/src/joulepai.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
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
|
+
|
|
4
6
|
export const JOULEPAI_BASE = "https://joulepai.ai/api/v1";
|
|
5
7
|
|
|
6
8
|
const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
@@ -51,6 +53,9 @@ export class JoulepaiSubmodule {
|
|
|
51
53
|
}
|
|
52
54
|
|
|
53
55
|
async balance() {
|
|
56
|
+
if (this._t.isGreenlandaiAgentKey) {
|
|
57
|
+
return (await this._t.request(GLDAI_BASE, "GET", "/api/v1/agent/me/balance", {})).balance_joules;
|
|
58
|
+
}
|
|
54
59
|
return (await this._t.request(this._base, "GET", "/wallet/balance/{wid}",
|
|
55
60
|
{ pathParams: { wid: await this._ensureId() } })).balance;
|
|
56
61
|
}
|
|
@@ -58,9 +63,11 @@ export class JoulepaiSubmodule {
|
|
|
58
63
|
/** Given a planned `cost` (e.g. a quote's joules_all_in from client.gldai.billingQuote), read a balance
|
|
59
64
|
* and return { needed, have, shortfall, can_afford } — the SDK twin of the MCP `joules_deficit` tool.
|
|
60
65
|
* Defaults to the authenticated wallet; pass `walletId` to check a specific wallet (parity with the MCP
|
|
61
|
-
* joules_deficit(wallet_id, cost) signature).
|
|
66
|
+
* joules_deficit(wallet_id, cost) signature). For a GreenlandAI agent key (gai_/gqa_) the balance is
|
|
67
|
+
* always the agent's OWN (GreenlandAI's agent-self endpoint is own-wallet only), so `walletId` is
|
|
68
|
+
* ignored for those keys. */
|
|
62
69
|
async deficit(cost, walletId = null) {
|
|
63
|
-
const have = walletId != null
|
|
70
|
+
const have = (walletId != null && !this._t.isGreenlandaiAgentKey)
|
|
64
71
|
? (await this._t.request(this._base, "GET", "/wallet/balance/{wid}", { pathParams: { wid: walletId } })).balance
|
|
65
72
|
: await this.balance();
|
|
66
73
|
const shortfall = Math.max(0, Number(cost) - Number(have));
|