@withgateway/sdk 0.2.8 → 0.2.9

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.
Files changed (45) hide show
  1. package/README.md +24 -8
  2. package/dist/cli.js +332 -163
  3. package/dist/cli.js.map +1 -1
  4. package/dist/cli.mjs +332 -163
  5. package/dist/cli.mjs.map +1 -1
  6. package/dist/files/index.js +119 -15
  7. package/dist/files/index.js.map +1 -1
  8. package/dist/files/index.mjs +119 -15
  9. package/dist/files/index.mjs.map +1 -1
  10. package/dist/index.d.mts +1 -1
  11. package/dist/index.d.ts +1 -1
  12. package/dist/index.js +229 -120
  13. package/dist/index.js.map +1 -1
  14. package/dist/index.mjs +220 -120
  15. package/dist/index.mjs.map +1 -1
  16. package/dist/traces/index.js +119 -15
  17. package/dist/traces/index.js.map +1 -1
  18. package/dist/traces/index.mjs +119 -15
  19. package/dist/traces/index.mjs.map +1 -1
  20. package/dist/tracing/index.js +1 -1
  21. package/dist/tracing/index.js.map +1 -1
  22. package/dist/tracing/index.mjs +1 -1
  23. package/dist/tracing/index.mjs.map +1 -1
  24. package/dist/worlds/index.d.mts +78 -9
  25. package/dist/worlds/index.d.ts +78 -9
  26. package/dist/worlds/index.js +219 -119
  27. package/dist/worlds/index.js.map +1 -1
  28. package/dist/worlds/index.mjs +220 -120
  29. package/dist/worlds/index.mjs.map +1 -1
  30. package/package.json +1 -1
  31. package/runtime/gatewaysdk/environment/_toml.py +3 -10
  32. package/runtime/gatewaysdk/environment/schema/skills/benchmarks-getting-started/SKILL.md +3 -3
  33. package/runtime/gatewaysdk/environment/schema/skills/connector-schema-authoring/SKILL.md +1 -1
  34. package/runtime/gatewaysdk/environment/schema/skills/worlds-getting-started/SKILL.md +11 -11
  35. package/runtime/gatewaysdk/environment/schema/skills/worlds-getting-started/references/cli-mcp-map.md +3 -2
  36. package/runtime/gatewaysdk/environment/schema/skills/worlds-getting-started/references/gotchas.md +5 -1
  37. package/runtime/gatewaysdk/environment/schema/skills/worlds-getting-started/references/new-world-sandbox.md +5 -3
  38. package/runtime/gatewaysdk/environment/schema/store.py +15 -6
  39. package/skills/benchmarks-getting-started/SKILL.md +3 -3
  40. package/skills/connector-schema-authoring/SKILL.md +1 -1
  41. package/skills/connector-schema-authoring/world-schema.md +1 -1
  42. package/skills/worlds-getting-started/SKILL.md +11 -11
  43. package/skills/worlds-getting-started/references/cli-mcp-map.md +3 -2
  44. package/skills/worlds-getting-started/references/gotchas.md +5 -1
  45. package/skills/worlds-getting-started/references/new-world-sandbox.md +5 -3
@@ -35,6 +35,115 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
35
35
  ));
36
36
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
37
37
 
38
+ // src/worlds/transport.ts
39
+ function platformTimeoutMs(env = process.env) {
40
+ const raw = env[PLATFORM_TIMEOUT_ENV];
41
+ if (raw === void 0 || raw === "") return PLATFORM_TIMEOUT_DEFAULT_MS;
42
+ const value = Number(raw);
43
+ if (Number.isInteger(value) && value > 0) return value;
44
+ throw new Error(`${PLATFORM_TIMEOUT_ENV} must be a positive whole number of milliseconds, not \`${raw}\`.`);
45
+ }
46
+ var PLATFORM_TIMEOUT_ENV, PLATFORM_TIMEOUT_DEFAULT_MS, CHECK_HOST, RETRY, CAUSES, UNKNOWN_CAUSE, TransportCause, UnreachableError, PlatformTransport;
47
+ var init_transport = __esm({
48
+ "src/worlds/transport.ts"() {
49
+ "use strict";
50
+ PLATFORM_TIMEOUT_ENV = "GATEWAY_TIMEOUT_MS";
51
+ PLATFORM_TIMEOUT_DEFAULT_MS = 12e4;
52
+ CHECK_HOST = "Check GATEWAY_HOST (or --host) points at a running platform, then retry.";
53
+ RETRY = "Retry; if it repeats, check the network between here and the platform.";
54
+ CAUSES = {
55
+ ECONNREFUSED: { reason: "connection refused", next: CHECK_HOST },
56
+ ENOTFOUND: { reason: "DNS lookup failed", next: CHECK_HOST },
57
+ EAI_AGAIN: { reason: "DNS lookup failed", next: CHECK_HOST },
58
+ ETIMEDOUT: { reason: "connect timed out", next: CHECK_HOST },
59
+ UND_ERR_CONNECT_TIMEOUT: { reason: "connect timed out", next: CHECK_HOST },
60
+ EHOSTUNREACH: { reason: "host unreachable", next: CHECK_HOST },
61
+ ENETUNREACH: { reason: "network unreachable", next: RETRY },
62
+ ECONNRESET: { reason: "connection dropped", next: RETRY },
63
+ UND_ERR_SOCKET: { reason: "connection dropped", next: RETRY },
64
+ EPIPE: { reason: "connection dropped", next: RETRY }
65
+ };
66
+ UNKNOWN_CAUSE = { reason: "network error", next: CHECK_HOST };
67
+ TransportCause = class _TransportCause {
68
+ constructor(reason, detail, next) {
69
+ this.reason = reason;
70
+ this.detail = detail;
71
+ this.next = next;
72
+ }
73
+ reason;
74
+ detail;
75
+ next;
76
+ static timeout(timeoutMs) {
77
+ return new _TransportCause(
78
+ `timed out after ${timeoutMs / 1e3}s`,
79
+ null,
80
+ `Retry; if the platform is slow, raise ${PLATFORM_TIMEOUT_ENV} (milliseconds per request).`
81
+ );
82
+ }
83
+ static of(error) {
84
+ const cause = error instanceof Error && error.cause instanceof Error ? error.cause : void 0;
85
+ const code = cause && "code" in cause && typeof cause.code === "string" ? cause.code : null;
86
+ const message = cause?.message ?? (error instanceof Error ? error.message : String(error));
87
+ const known = code && CAUSES[code] || UNKNOWN_CAUSE;
88
+ return new _TransportCause(known.reason, code ? `${code}: ${message}` : message, known.next);
89
+ }
90
+ describe() {
91
+ return this.detail === null ? this.reason : `${this.reason} (${this.detail})`;
92
+ }
93
+ };
94
+ UnreachableError = class extends Error {
95
+ constructor(host, method, route, failure) {
96
+ super(`${method} ${route}: no answer from ${host}: ${failure.describe()}. ${failure.next}`);
97
+ this.host = host;
98
+ this.method = method;
99
+ this.route = route;
100
+ this.failure = failure;
101
+ this.name = "UnreachableError";
102
+ }
103
+ host;
104
+ method;
105
+ route;
106
+ failure;
107
+ };
108
+ PlatformTransport = class {
109
+ constructor(endpoint, timeoutMs = platformTimeoutMs()) {
110
+ this.endpoint = endpoint;
111
+ this.timeoutMs = timeoutMs;
112
+ }
113
+ endpoint;
114
+ timeoutMs;
115
+ /** A request that legitimately takes longer (a sandbox exec, a world create) waits its own budget; every other one waits the default. */
116
+ budget(ownMs) {
117
+ return Math.max(ownMs ?? 0, this.timeoutMs);
118
+ }
119
+ async send(method, route, body, opts = {}) {
120
+ const timeoutMs = this.budget(opts.timeoutMs);
121
+ const payload = body === void 0 ? {} : { body: JSON.stringify(body) };
122
+ const controller = new AbortController();
123
+ const timer = setTimeout(() => controller.abort(), timeoutMs);
124
+ try {
125
+ const res = await fetch(`${this.endpoint.host}${route}`, {
126
+ method,
127
+ headers: {
128
+ "content-type": "application/json",
129
+ accept: "application/json",
130
+ authorization: "Basic " + Buffer.from(`${this.endpoint.publicKey}:${this.endpoint.secretKey}`).toString("base64")
131
+ },
132
+ ...payload,
133
+ signal: controller.signal
134
+ });
135
+ return { status: res.status, ok: res.ok, text: await res.text() };
136
+ } catch (error) {
137
+ const cause = controller.signal.aborted ? TransportCause.timeout(timeoutMs) : TransportCause.of(error);
138
+ throw new UnreachableError(this.endpoint.host, method, route, cause);
139
+ } finally {
140
+ clearTimeout(timer);
141
+ }
142
+ }
143
+ };
144
+ }
145
+ });
146
+
38
147
  // src/worlds/browserReconnect.ts
39
148
  var init_browserReconnect = __esm({
40
149
  "src/worlds/browserReconnect.ts"() {
@@ -366,24 +475,17 @@ function parseErrorBody(text, limit = 600) {
366
475
  code: stableCode
367
476
  };
368
477
  }
369
- async function apiRequest(options, method, path8, body) {
370
- const { host, publicKey, secretKey } = resolveEnv(options);
371
- const res = await fetch(`${host}${path8}`, {
372
- method,
373
- headers: {
374
- "content-type": "application/json",
375
- authorization: "Basic " + Buffer.from(`${publicKey}:${secretKey}`).toString("base64")
376
- },
377
- ...body === void 0 ? {} : { body: JSON.stringify(body) }
378
- });
379
- const text = await res.text();
380
- if (!res.ok) throw new ApiError(res.status, method, path8, text);
381
- return JSON.parse(text);
478
+ async function apiRequest(options, method, path8, body, init = {}) {
479
+ const reply = await new PlatformTransport(resolveEnv(options)).send(method, path8, body, init);
480
+ if (!reply.ok) throw new ApiError(reply.status, method, path8, reply.text);
481
+ return JSON.parse(reply.text);
382
482
  }
383
483
  var ApiError;
384
484
  var init_worlds = __esm({
385
485
  "src/worlds/index.ts"() {
386
486
  "use strict";
487
+ init_transport();
488
+ init_transport();
387
489
  init_session();
388
490
  init_sessionList();
389
491
  init_sessionContract();
@@ -408,14 +510,16 @@ var init_worlds = __esm({
408
510
  init_editSessions();
409
511
  init_dryRun();
410
512
  ApiError = class extends Error {
411
- constructor(status, method, path8, body) {
412
- const parsed = parseErrorBody(body);
513
+ constructor(status, method, path8, text) {
514
+ const parsed = parseErrorBody(text);
413
515
  super(`${method} ${path8} -> ${status}: ${parsed.detail}`);
414
516
  this.status = status;
517
+ this.text = text;
415
518
  this.name = "ApiError";
416
519
  this.code = parsed.code;
417
520
  }
418
521
  status;
522
+ text;
419
523
  code;
420
524
  };
421
525
  }