@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
@@ -10,6 +10,115 @@ var __esm = (fn, res, err) => function __init() {
10
10
  }
11
11
  };
12
12
 
13
+ // src/worlds/transport.ts
14
+ function platformTimeoutMs(env = process.env) {
15
+ const raw = env[PLATFORM_TIMEOUT_ENV];
16
+ if (raw === void 0 || raw === "") return PLATFORM_TIMEOUT_DEFAULT_MS;
17
+ const value = Number(raw);
18
+ if (Number.isInteger(value) && value > 0) return value;
19
+ throw new Error(`${PLATFORM_TIMEOUT_ENV} must be a positive whole number of milliseconds, not \`${raw}\`.`);
20
+ }
21
+ var PLATFORM_TIMEOUT_ENV, PLATFORM_TIMEOUT_DEFAULT_MS, CHECK_HOST, RETRY, CAUSES, UNKNOWN_CAUSE, TransportCause, UnreachableError, PlatformTransport;
22
+ var init_transport = __esm({
23
+ "src/worlds/transport.ts"() {
24
+ "use strict";
25
+ PLATFORM_TIMEOUT_ENV = "GATEWAY_TIMEOUT_MS";
26
+ PLATFORM_TIMEOUT_DEFAULT_MS = 12e4;
27
+ CHECK_HOST = "Check GATEWAY_HOST (or --host) points at a running platform, then retry.";
28
+ RETRY = "Retry; if it repeats, check the network between here and the platform.";
29
+ CAUSES = {
30
+ ECONNREFUSED: { reason: "connection refused", next: CHECK_HOST },
31
+ ENOTFOUND: { reason: "DNS lookup failed", next: CHECK_HOST },
32
+ EAI_AGAIN: { reason: "DNS lookup failed", next: CHECK_HOST },
33
+ ETIMEDOUT: { reason: "connect timed out", next: CHECK_HOST },
34
+ UND_ERR_CONNECT_TIMEOUT: { reason: "connect timed out", next: CHECK_HOST },
35
+ EHOSTUNREACH: { reason: "host unreachable", next: CHECK_HOST },
36
+ ENETUNREACH: { reason: "network unreachable", next: RETRY },
37
+ ECONNRESET: { reason: "connection dropped", next: RETRY },
38
+ UND_ERR_SOCKET: { reason: "connection dropped", next: RETRY },
39
+ EPIPE: { reason: "connection dropped", next: RETRY }
40
+ };
41
+ UNKNOWN_CAUSE = { reason: "network error", next: CHECK_HOST };
42
+ TransportCause = class _TransportCause {
43
+ constructor(reason, detail, next) {
44
+ this.reason = reason;
45
+ this.detail = detail;
46
+ this.next = next;
47
+ }
48
+ reason;
49
+ detail;
50
+ next;
51
+ static timeout(timeoutMs) {
52
+ return new _TransportCause(
53
+ `timed out after ${timeoutMs / 1e3}s`,
54
+ null,
55
+ `Retry; if the platform is slow, raise ${PLATFORM_TIMEOUT_ENV} (milliseconds per request).`
56
+ );
57
+ }
58
+ static of(error) {
59
+ const cause = error instanceof Error && error.cause instanceof Error ? error.cause : void 0;
60
+ const code = cause && "code" in cause && typeof cause.code === "string" ? cause.code : null;
61
+ const message = cause?.message ?? (error instanceof Error ? error.message : String(error));
62
+ const known = code && CAUSES[code] || UNKNOWN_CAUSE;
63
+ return new _TransportCause(known.reason, code ? `${code}: ${message}` : message, known.next);
64
+ }
65
+ describe() {
66
+ return this.detail === null ? this.reason : `${this.reason} (${this.detail})`;
67
+ }
68
+ };
69
+ UnreachableError = class extends Error {
70
+ constructor(host, method, route, failure) {
71
+ super(`${method} ${route}: no answer from ${host}: ${failure.describe()}. ${failure.next}`);
72
+ this.host = host;
73
+ this.method = method;
74
+ this.route = route;
75
+ this.failure = failure;
76
+ this.name = "UnreachableError";
77
+ }
78
+ host;
79
+ method;
80
+ route;
81
+ failure;
82
+ };
83
+ PlatformTransport = class {
84
+ constructor(endpoint, timeoutMs = platformTimeoutMs()) {
85
+ this.endpoint = endpoint;
86
+ this.timeoutMs = timeoutMs;
87
+ }
88
+ endpoint;
89
+ timeoutMs;
90
+ /** A request that legitimately takes longer (a sandbox exec, a world create) waits its own budget; every other one waits the default. */
91
+ budget(ownMs) {
92
+ return Math.max(ownMs ?? 0, this.timeoutMs);
93
+ }
94
+ async send(method, route, body, opts = {}) {
95
+ const timeoutMs = this.budget(opts.timeoutMs);
96
+ const payload = body === void 0 ? {} : { body: JSON.stringify(body) };
97
+ const controller = new AbortController();
98
+ const timer = setTimeout(() => controller.abort(), timeoutMs);
99
+ try {
100
+ const res = await fetch(`${this.endpoint.host}${route}`, {
101
+ method,
102
+ headers: {
103
+ "content-type": "application/json",
104
+ accept: "application/json",
105
+ authorization: "Basic " + Buffer.from(`${this.endpoint.publicKey}:${this.endpoint.secretKey}`).toString("base64")
106
+ },
107
+ ...payload,
108
+ signal: controller.signal
109
+ });
110
+ return { status: res.status, ok: res.ok, text: await res.text() };
111
+ } catch (error) {
112
+ const cause = controller.signal.aborted ? TransportCause.timeout(timeoutMs) : TransportCause.of(error);
113
+ throw new UnreachableError(this.endpoint.host, method, route, cause);
114
+ } finally {
115
+ clearTimeout(timer);
116
+ }
117
+ }
118
+ };
119
+ }
120
+ });
121
+
13
122
  // src/worlds/browserReconnect.ts
14
123
  var init_browserReconnect = __esm({
15
124
  "src/worlds/browserReconnect.ts"() {
@@ -335,24 +444,17 @@ function parseErrorBody(text, limit = 600) {
335
444
  code: stableCode
336
445
  };
337
446
  }
338
- async function apiRequest(options, method, path8, body) {
339
- const { host, publicKey, secretKey } = resolveEnv(options);
340
- const res = await fetch(`${host}${path8}`, {
341
- method,
342
- headers: {
343
- "content-type": "application/json",
344
- authorization: "Basic " + Buffer.from(`${publicKey}:${secretKey}`).toString("base64")
345
- },
346
- ...body === void 0 ? {} : { body: JSON.stringify(body) }
347
- });
348
- const text = await res.text();
349
- if (!res.ok) throw new ApiError(res.status, method, path8, text);
350
- return JSON.parse(text);
447
+ async function apiRequest(options, method, path8, body, init = {}) {
448
+ const reply = await new PlatformTransport(resolveEnv(options)).send(method, path8, body, init);
449
+ if (!reply.ok) throw new ApiError(reply.status, method, path8, reply.text);
450
+ return JSON.parse(reply.text);
351
451
  }
352
452
  var ApiError;
353
453
  var init_worlds = __esm({
354
454
  "src/worlds/index.ts"() {
355
455
  "use strict";
456
+ init_transport();
457
+ init_transport();
356
458
  init_session();
357
459
  init_sessionList();
358
460
  init_sessionContract();
@@ -377,14 +479,16 @@ var init_worlds = __esm({
377
479
  init_editSessions();
378
480
  init_dryRun();
379
481
  ApiError = class extends Error {
380
- constructor(status, method, path8, body) {
381
- const parsed = parseErrorBody(body);
482
+ constructor(status, method, path8, text) {
483
+ const parsed = parseErrorBody(text);
382
484
  super(`${method} ${path8} -> ${status}: ${parsed.detail}`);
383
485
  this.status = status;
486
+ this.text = text;
384
487
  this.name = "ApiError";
385
488
  this.code = parsed.code;
386
489
  }
387
490
  status;
491
+ text;
388
492
  code;
389
493
  };
390
494
  }