@greenlandai/sdk 0.5.1 → 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 CHANGED
@@ -116,6 +116,7 @@ var IDEMPOTENCY_MAP = {
116
116
  "GET /api/v1/look.from": { field: "X-Idempotency-Key", placement: "header", tier: ENFORCED },
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
+ "GET /api/v1/map.viewport": { field: "X-Idempotency-Key", placement: "header", tier: ENFORCED },
119
120
  // (cf) ENYAL metered GET — joins Class C header class (server reads X-Idempotency-Key per the Option-B switch)
120
121
  "GET /api/v1/search": { field: "X-Idempotency-Key", placement: "header", tier: ENFORCED },
121
122
  // Class D — transfer-class
@@ -204,6 +205,13 @@ var Transport = class {
204
205
  this.metrics = metrics || null;
205
206
  this._fetch = fetchImpl || fetch;
206
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
+ }
207
215
  async request(baseUrl, method, pathTemplate, {
208
216
  pathParams = {},
209
217
  body = null,
@@ -3966,6 +3974,207 @@ var EnyalSubmodule = class {
3966
3974
  }
3967
3975
  };
3968
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
+
3969
4178
  // src/joulepai.js
3970
4179
  var JOULEPAI_BASE = "https://joulepai.ai/api/v1";
3971
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;
@@ -4020,6 +4229,9 @@ var JoulepaiSubmodule = class {
4020
4229
  );
4021
4230
  }
4022
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
+ }
4023
4235
  return (await this._t.request(
4024
4236
  this._base,
4025
4237
  "GET",
@@ -4027,11 +4239,14 @@ var JoulepaiSubmodule = class {
4027
4239
  { pathParams: { wid: await this._ensureId() } }
4028
4240
  )).balance;
4029
4241
  }
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();
4242
+ /** Given a planned `cost` (e.g. a quote's joules_all_in from client.gldai.billingQuote), read a balance
4243
+ * and return { needed, have, shortfall, can_afford } — the SDK twin of the MCP `joules_deficit` tool.
4244
+ * Defaults to the authenticated wallet; pass `walletId` to check a specific wallet (parity with the MCP
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. */
4248
+ async deficit(cost, walletId = null) {
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();
4035
4250
  const shortfall = Math.max(0, Number(cost) - Number(have));
4036
4251
  return { needed: Number(cost), have: Number(have), shortfall, can_afford: shortfall === 0 };
4037
4252
  }
@@ -4330,184 +4545,8 @@ var RareeaiSubmodule = class {
4330
4545
  }
4331
4546
  };
4332
4547
 
4333
- // src/gldai.js
4334
- var GLDAI_BASE = "https://greenlandai.ai";
4335
- var GldaiSubmodule = class {
4336
- constructor(transport, baseUrl = GLDAI_BASE) {
4337
- this._t = transport;
4338
- this._base = baseUrl;
4339
- }
4340
- companies({ idempotencyKey, ...params } = {}) {
4341
- return this._t.request(this._base, "GET", "/api/v1/companies", { params, idempotencyKey });
4342
- }
4343
- company(companyId) {
4344
- return this._t.request(this._base, "GET", "/api/v1/companies/{cid}", { pathParams: { cid: companyId } });
4345
- }
4346
- deposits({ idempotencyKey, ...params } = {}) {
4347
- return this._t.request(this._base, "GET", "/api/v1/deposits", { params, idempotencyKey });
4348
- }
4349
- deposit(depositId) {
4350
- return this._t.request(this._base, "GET", "/api/v1/deposits/{did}", { pathParams: { did: depositId } });
4351
- }
4352
- infrastructureList({ idempotencyKey, ...params } = {}) {
4353
- return this._t.request(this._base, "GET", "/api/v1/infrastructure", { params, idempotencyKey });
4354
- }
4355
- infrastructure(infraId) {
4356
- return this._t.request(this._base, "GET", "/api/v1/infrastructure/{iid}", { pathParams: { iid: infraId } });
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. */
4364
- query(q, { idempotencyKey, ...params } = {}) {
4365
- return this._t.request(this._base, "GET", "/api/v1/query", { params: { q, ...params }, idempotencyKey });
4366
- }
4367
- projects({ idempotencyKey, ...params } = {}) {
4368
- return this._t.request(this._base, "GET", "/api/v1/projects", { params, idempotencyKey });
4369
- }
4370
- project(projectId) {
4371
- return this._t.request(this._base, "GET", "/api/v1/projects/{pid}", { pathParams: { pid: projectId } });
4372
- }
4373
- mapdata({ idempotencyKey, ...params } = {}) {
4374
- return this._t.request(this._base, "GET", "/api/v1/mapdata", { params, idempotencyKey });
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
- }
4436
- // ── contributor-programme reads (P-DAY.105) ──────────────────────
4437
- /** Your Bridge record (session): contribution units at your standing's weight, plus promoted work. */
4438
- agentBridge() {
4439
- return this._t.request(this._base, "GET", "/api/v1/agent/bridge", {});
4440
- }
4441
- /** Your seat record (session): kind, vesting clock, allotment counter. A recorded intent, not a
4442
- * share; nothing owed until Execution, which is not promised. */
4443
- agentSeat() {
4444
- return this._t.request(this._base, "GET", "/api/v1/agent/seat", {});
4445
- }
4446
- // ── Contributor programme grant management (TEN-13; P-DAY.106) ────
4447
- // SESSION-ONLY: build the Client with your signed-in greenlandai.ai session
4448
- // (oauthToken); an X-API-Key is refused 403. The submit/read methods below use X-API-Key.
4449
- /** Enable contribute on an identity you own. SESSION-ONLY — build the Client with your signed-in
4450
- * greenlandai.ai session (oauthToken), NOT an API key (a key is refused 403). target 'agent' grants
4451
- * one of your gqa_ agents (agentId required, the default+safest); 'self' grants your OWN gai_ key and
4452
- * requires acknowledgeWidenedKey=true. identity: 3-40 char slug. The grant lives on the identity,
4453
- * survives key regeneration, does not inherit. POST /api/v1/agent/contribute/enable. */
4454
- contributeEnable({ target, identity, agentId = null, acknowledgeWidenedKey = false }) {
4455
- const body = { target, identity, acknowledge_widened_key: acknowledgeWidenedKey };
4456
- if (agentId != null) body.agent_id = agentId;
4457
- return this._t.request(this._base, "POST", "/api/v1/agent/contribute/enable", { body });
4458
- }
4459
- /** Clear the contribute grant (contribute only; the key still works everywhere else). SESSION-ONLY.
4460
- * POST /api/v1/agent/contribute/disable. */
4461
- contributeDisable({ target, agentId = null }) {
4462
- const body = { target };
4463
- if (agentId != null) body.agent_id = agentId;
4464
- return this._t.request(this._base, "POST", "/api/v1/agent/contribute/disable", { body });
4465
- }
4466
- /** Grant status for your key and your active agents (is contribute enabled, under which identity).
4467
- * SESSION-ONLY. Never returns a key. GET /api/v1/agent/contribute. */
4468
- contributeGrantStatus() {
4469
- return this._t.request(this._base, "GET", "/api/v1/agent/contribute", {});
4470
- }
4471
- // ── Contributor door: submit + your own reads (X-API-Key) ─────────
4472
- // Build the Client with the gai_ key of an ENABLED identity. No agent_id is ever
4473
- // sent — the door derives your contributor identity from the key.
4474
- /** Submit evidenced relationships. Auth: X-API-Key — build the Client with the gai_ key of an ENABLED
4475
- * identity (contributeEnable first); the gqa_ agent ID is NOT sent, the door derives identity from
4476
- * the key. Each relation MUST carry subject, relation, object, source_url (a real http(s) page) and
4477
- * quote (verbatim, >= 15 chars — the judge refutes against it). entities proposes a new endpoint only
4478
- * alongside a relation that references it. Nothing is written on submit; claims queue for the nightly
4479
- * judge (21:15 UTC). results[].status: queued_for_judgement / bundled_with_proposed_entity · duplicate
4480
- * / already_pending · unmapped_relation · unresolved_subject|object (suggestions) · self_loop /
4481
- * source_excluded / invalid. The verdict — promoted, HELD or dismissed, with its reason — appears per
4482
- * item via contributeSubmissions(); the receipt via contributeReceipts(); HELD is not a failure, not
4483
- * counted until decided. Standing weights live at client.joulepai.programmeConfig() — not restated.
4484
- * POST /api/v1/contribute/relations. */
4485
- contributeSubmit(relations, { entities = null } = {}) {
4486
- const body = { relations };
4487
- if (entities != null) body.entities = entities;
4488
- return this._t.request(this._base, "POST", "/api/v1/contribute/relations", { body });
4489
- }
4490
- /** Your OWN contributor standing (X-API-Key of an enabled identity): totals, acceptanceRate,
4491
- * pending_review, refused_at_door, standing and the thresholds that apply after a floor of
4492
- * submissions. GET /api/v1/contribute/status. */
4493
- contributeStats() {
4494
- return this._t.request(this._base, "GET", "/api/v1/contribute/status", {});
4495
- }
4496
- /** Your OWN per-item submission outcomes (X-API-Key): each item's outcome (pending_review / accepted /
4497
- * rejected) with the judge's reason verbatim in review_note (a HELD item carries the reason).
4498
- * GET /api/v1/contribute/submissions. */
4499
- contributeSubmissions({ limit = 50, offset = 0 } = {}) {
4500
- return this._t.request(this._base, "GET", "/api/v1/contribute/submissions", { params: { limit, offset } });
4501
- }
4502
- /** Your OWN append-only contribution receipts (X-API-Key) — proof of what you submitted, with the
4503
- * canonical claim hash (claim_sha256). Own rows only. GET /api/v1/contribute/receipts. */
4504
- contributeReceipts({ limit = 50, offset = 0 } = {}) {
4505
- return this._t.request(this._base, "GET", "/api/v1/contribute/receipts", { params: { limit, offset } });
4506
- }
4507
- };
4508
-
4509
4548
  // index.js
4510
- var VERSION = "0.5.1";
4549
+ var VERSION = "0.5.3";
4511
4550
  var Client = class {
4512
4551
  /**
4513
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.1";
19
+ export const VERSION = "0.5.3";
20
20
 
21
21
  export class Client {
22
22
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@greenlandai/sdk",
3
- "version": "0.5.1",
3
+ "version": "0.5.3",
4
4
  "description": "Unified SDK for the GreenlandAI ecosystem (ENYAL, JoulePAI, RAREEAI, GreenlandAI)",
5
5
  "license": "Apache-2.0",
6
6
  "homepage": "https://enyal.ai",
@@ -43,6 +43,7 @@ export const IDEMPOTENCY_MAP = {
43
43
  "GET /api/v1/look.from": { field: "X-Idempotency-Key", placement: "header", tier: ENFORCED },
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
+ "GET /api/v1/map.viewport": { field: "X-Idempotency-Key", placement: "header", tier: ENFORCED },
46
47
  // (cf) ENYAL metered GET — joins Class C header class (server reads X-Idempotency-Key per the Option-B switch)
47
48
  "GET /api/v1/search": { field: "X-Idempotency-Key", placement: "header", tier: ENFORCED },
48
49
  // Class D — transfer-class
@@ -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/gldai.js CHANGED
@@ -67,8 +67,9 @@ export class GldaiSubmodule {
67
67
  }
68
68
  /** GET /api/v1/look.from — companies/infrastructure near a point (lat+lng) or anchored on one entity
69
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. */
70
+ * billingQuote). entityType behaves two ways (backend 2026-09-14): entityType ALONE (with lat/lng)
71
+ * FILTERS the frame to that type; entityType + id ANCHORS the pose at that entity and keeps ALL types;
72
+ * an unknown entityType is a 400 before any charge. Same as the MCP `look_from` tool. */
72
73
  lookFrom({ lat, lng, entityType, id, radiusKm = 100, energy = false,
73
74
  includeCountryCentroids = false, idempotencyKey } = {}) {
74
75
  const params = { radius_km: radiusKm, energy, include_country_centroids: includeCountryCentroids };
@@ -97,6 +98,22 @@ export class GldaiSubmodule {
97
98
  if (search) params.search = search;
98
99
  return this._t.request(this._base, "GET", "/api/v1/relationships", { params, idempotencyKey });
99
100
  }
101
+ /** GET /api/v1/map.viewport — everything inside a bounding box (THE SCREEN): capped, id-ordered `pins`
102
+ * + `counts_by_type` (counts are the TRUE totals for the whole bbox; pins are a sample). Params:
103
+ * minLat/minLng/maxLat/maxLng (the bbox), entityType (deposit|infrastructure|company|project — default
104
+ * all four), energy (default false), includeCountryCentroids (default false). AGENT KEYS ONLY; metered
105
+ * against the CALLING agent's wallet (quote with billingQuote); pins do NOT count against your entity
106
+ * cap. Same as the MCP `map_viewport` tool. Use this — the old /mapdata bulk surface is CLOSED. */
107
+ mapViewport({ minLat, minLng, maxLat, maxLng, entityType, energy = false,
108
+ includeCountryCentroids = false, idempotencyKey } = {}) {
109
+ const params = { energy, include_country_centroids: includeCountryCentroids };
110
+ if (minLat != null) params.min_lat = minLat;
111
+ if (minLng != null) params.min_lng = minLng;
112
+ if (maxLat != null) params.max_lat = maxLat;
113
+ if (maxLng != null) params.max_lng = maxLng;
114
+ if (entityType != null) params.entity_type = entityType;
115
+ return this._t.request(this._base, "GET", "/api/v1/map.viewport", { params, idempotencyKey });
116
+ }
100
117
 
101
118
  // ── contributor-programme reads (P-DAY.105) ──────────────────────
102
119
  /** Your Bridge record (session): contribution units at your standing's weight, plus promoted work. */
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,15 +53,23 @@ 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
  }
57
62
 
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
+ /** Given a planned `cost` (e.g. a quote's joules_all_in from client.gldai.billingQuote), read a balance
64
+ * and return { needed, have, shortfall, can_afford } — the SDK twin of the MCP `joules_deficit` tool.
65
+ * Defaults to the authenticated wallet; pass `walletId` to check a specific wallet (parity with the MCP
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. */
69
+ async deficit(cost, walletId = null) {
70
+ const have = (walletId != null && !this._t.isGreenlandaiAgentKey)
71
+ ? (await this._t.request(this._base, "GET", "/wallet/balance/{wid}", { pathParams: { wid: walletId } })).balance
72
+ : await this.balance();
63
73
  const shortfall = Math.max(0, Number(cost) - Number(have));
64
74
  return { needed: Number(cost), have: Number(have), shortfall, can_afford: shortfall === 0 };
65
75
  }