@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
@@ -42,6 +42,115 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
42
42
  ));
43
43
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
44
44
 
45
+ // src/worlds/transport.ts
46
+ function platformTimeoutMs(env = process.env) {
47
+ const raw = env[PLATFORM_TIMEOUT_ENV];
48
+ if (raw === void 0 || raw === "") return PLATFORM_TIMEOUT_DEFAULT_MS;
49
+ const value = Number(raw);
50
+ if (Number.isInteger(value) && value > 0) return value;
51
+ throw new Error(`${PLATFORM_TIMEOUT_ENV} must be a positive whole number of milliseconds, not \`${raw}\`.`);
52
+ }
53
+ var PLATFORM_TIMEOUT_ENV, PLATFORM_TIMEOUT_DEFAULT_MS, CHECK_HOST, RETRY, CAUSES, UNKNOWN_CAUSE, TransportCause, UnreachableError, PlatformTransport;
54
+ var init_transport = __esm({
55
+ "src/worlds/transport.ts"() {
56
+ "use strict";
57
+ PLATFORM_TIMEOUT_ENV = "GATEWAY_TIMEOUT_MS";
58
+ PLATFORM_TIMEOUT_DEFAULT_MS = 12e4;
59
+ CHECK_HOST = "Check GATEWAY_HOST (or --host) points at a running platform, then retry.";
60
+ RETRY = "Retry; if it repeats, check the network between here and the platform.";
61
+ CAUSES = {
62
+ ECONNREFUSED: { reason: "connection refused", next: CHECK_HOST },
63
+ ENOTFOUND: { reason: "DNS lookup failed", next: CHECK_HOST },
64
+ EAI_AGAIN: { reason: "DNS lookup failed", next: CHECK_HOST },
65
+ ETIMEDOUT: { reason: "connect timed out", next: CHECK_HOST },
66
+ UND_ERR_CONNECT_TIMEOUT: { reason: "connect timed out", next: CHECK_HOST },
67
+ EHOSTUNREACH: { reason: "host unreachable", next: CHECK_HOST },
68
+ ENETUNREACH: { reason: "network unreachable", next: RETRY },
69
+ ECONNRESET: { reason: "connection dropped", next: RETRY },
70
+ UND_ERR_SOCKET: { reason: "connection dropped", next: RETRY },
71
+ EPIPE: { reason: "connection dropped", next: RETRY }
72
+ };
73
+ UNKNOWN_CAUSE = { reason: "network error", next: CHECK_HOST };
74
+ TransportCause = class _TransportCause {
75
+ constructor(reason, detail, next) {
76
+ this.reason = reason;
77
+ this.detail = detail;
78
+ this.next = next;
79
+ }
80
+ reason;
81
+ detail;
82
+ next;
83
+ static timeout(timeoutMs) {
84
+ return new _TransportCause(
85
+ `timed out after ${timeoutMs / 1e3}s`,
86
+ null,
87
+ `Retry; if the platform is slow, raise ${PLATFORM_TIMEOUT_ENV} (milliseconds per request).`
88
+ );
89
+ }
90
+ static of(error) {
91
+ const cause = error instanceof Error && error.cause instanceof Error ? error.cause : void 0;
92
+ const code = cause && "code" in cause && typeof cause.code === "string" ? cause.code : null;
93
+ const message = cause?.message ?? (error instanceof Error ? error.message : String(error));
94
+ const known = code && CAUSES[code] || UNKNOWN_CAUSE;
95
+ return new _TransportCause(known.reason, code ? `${code}: ${message}` : message, known.next);
96
+ }
97
+ describe() {
98
+ return this.detail === null ? this.reason : `${this.reason} (${this.detail})`;
99
+ }
100
+ };
101
+ UnreachableError = class extends Error {
102
+ constructor(host, method, route, failure) {
103
+ super(`${method} ${route}: no answer from ${host}: ${failure.describe()}. ${failure.next}`);
104
+ this.host = host;
105
+ this.method = method;
106
+ this.route = route;
107
+ this.failure = failure;
108
+ this.name = "UnreachableError";
109
+ }
110
+ host;
111
+ method;
112
+ route;
113
+ failure;
114
+ };
115
+ PlatformTransport = class {
116
+ constructor(endpoint, timeoutMs = platformTimeoutMs()) {
117
+ this.endpoint = endpoint;
118
+ this.timeoutMs = timeoutMs;
119
+ }
120
+ endpoint;
121
+ timeoutMs;
122
+ /** A request that legitimately takes longer (a sandbox exec, a world create) waits its own budget; every other one waits the default. */
123
+ budget(ownMs) {
124
+ return Math.max(ownMs ?? 0, this.timeoutMs);
125
+ }
126
+ async send(method, route, body, opts = {}) {
127
+ const timeoutMs = this.budget(opts.timeoutMs);
128
+ const payload = body === void 0 ? {} : { body: JSON.stringify(body) };
129
+ const controller = new AbortController();
130
+ const timer = setTimeout(() => controller.abort(), timeoutMs);
131
+ try {
132
+ const res = await fetch(`${this.endpoint.host}${route}`, {
133
+ method,
134
+ headers: {
135
+ "content-type": "application/json",
136
+ accept: "application/json",
137
+ authorization: "Basic " + Buffer.from(`${this.endpoint.publicKey}:${this.endpoint.secretKey}`).toString("base64")
138
+ },
139
+ ...payload,
140
+ signal: controller.signal
141
+ });
142
+ return { status: res.status, ok: res.ok, text: await res.text() };
143
+ } catch (error) {
144
+ const cause = controller.signal.aborted ? TransportCause.timeout(timeoutMs) : TransportCause.of(error);
145
+ throw new UnreachableError(this.endpoint.host, method, route, cause);
146
+ } finally {
147
+ clearTimeout(timer);
148
+ }
149
+ }
150
+ };
151
+ }
152
+ });
153
+
45
154
  // src/worlds/browserReconnect.ts
46
155
  async function closeConnection(c) {
47
156
  await c.context.close();
@@ -2433,7 +2542,7 @@ var require_package = __commonJS({
2433
2542
  "package.json"(exports2, module2) {
2434
2543
  module2.exports = {
2435
2544
  name: "@withgateway/sdk",
2436
- version: "0.2.8",
2545
+ version: "0.2.9",
2437
2546
  description: "Gateway SDK for TypeScript - A/B experiments, tracing, and observability",
2438
2547
  main: "./dist/index.js",
2439
2548
  module: "./dist/index.mjs",
@@ -4538,6 +4647,34 @@ function parseSlugRef(slugRef) {
4538
4647
  if (at === -1) return { slug: slugRef };
4539
4648
  return { slug: slugRef.slice(0, at), ref: slugRef.slice(at + 1) };
4540
4649
  }
4650
+ function rebaseConflicts(error) {
4651
+ if (!(error instanceof ApiError) || error.status !== 409) return null;
4652
+ let body;
4653
+ try {
4654
+ body = JSON.parse(error.text);
4655
+ } catch {
4656
+ return null;
4657
+ }
4658
+ const conflicts = body?.conflicts;
4659
+ if (!Array.isArray(conflicts)) return null;
4660
+ return conflicts.filter(isConflictPath).map(({ path: path12, reason }) => ({ path: path12, reason }));
4661
+ }
4662
+ function isConflictPath(value) {
4663
+ const entry = value;
4664
+ return typeof entry?.path === "string" && typeof entry.reason === "string";
4665
+ }
4666
+ function uncommittedPaths(error) {
4667
+ if (!(error instanceof ApiError) || error.status !== 409 || error.code !== "sandbox_uncommitted") return null;
4668
+ let body;
4669
+ try {
4670
+ body = JSON.parse(error.text);
4671
+ } catch {
4672
+ return null;
4673
+ }
4674
+ const uncommitted = body?.uncommitted;
4675
+ if (!Array.isArray(uncommitted)) return null;
4676
+ return uncommitted.filter((p) => typeof p === "string");
4677
+ }
4541
4678
  function listQuery(filter) {
4542
4679
  const params = new URLSearchParams();
4543
4680
  if (filter.status) params.set("status", filter.status);
@@ -4546,18 +4683,25 @@ function listQuery(filter) {
4546
4683
  const qs = params.toString();
4547
4684
  return qs ? `?${qs}` : "";
4548
4685
  }
4549
- var isSandboxImportPending, sid, WorldSandboxClient;
4686
+ var isSandboxImportPending, sid, SANDBOXES, SANDBOX_REQUEST_TIMEOUT_MS, WorldSandboxClient;
4550
4687
  var init_sandbox = __esm({
4551
4688
  "src/worlds/sandbox.ts"() {
4552
4689
  "use strict";
4553
4690
  init_worlds();
4554
4691
  isSandboxImportPending = (answer) => !("versionId" in answer);
4555
4692
  sid = encodeURIComponent;
4693
+ SANDBOXES = "/api/public/benchmark-containers/sandboxes";
4694
+ SANDBOX_REQUEST_TIMEOUT_MS = 66e4;
4556
4695
  WorldSandboxClient = class {
4557
4696
  constructor(options = {}) {
4558
4697
  this.options = options;
4559
4698
  }
4560
4699
  options;
4700
+ request(method, path12, body) {
4701
+ return apiRequest(this.options, method, path12, body, {
4702
+ timeoutMs: SANDBOX_REQUEST_TIMEOUT_MS
4703
+ });
4704
+ }
4561
4705
  /**
4562
4706
  * `{ slug, ref? }` opens a READY version; `{ new, from }` opens a sandbox on
4563
4707
  * a world that does not exist yet (409 `world_exists` if the slug is taken,
@@ -4565,42 +4709,39 @@ var init_sandbox = __esm({
4565
4709
  * creates the world on `main`.
4566
4710
  */
4567
4711
  open(target) {
4568
- return apiRequest(this.options, "POST", "/api/public/benchmark-containers/sandboxes", target);
4712
+ return this.request("POST", `${SANDBOXES}`, target);
4569
4713
  }
4570
4714
  status(sandboxId) {
4571
- return apiRequest(this.options, "GET", `/api/public/benchmark-containers/sandboxes/${sid(sandboxId)}`);
4715
+ return this.request("GET", `${SANDBOXES}/${sid(sandboxId)}`);
4572
4716
  }
4573
4717
  /** The project's sandboxes, newest first — how an agent finds one it left open. */
4574
4718
  async list(filter = {}) {
4575
- const res = await apiRequest(
4576
- this.options,
4577
- "GET",
4578
- `/api/public/benchmark-containers/sandboxes${listQuery(filter)}`
4579
- );
4719
+ const res = await this.request("GET", `${SANDBOXES}${listQuery(filter)}`);
4580
4720
  return res.sandboxes;
4581
4721
  }
4582
4722
  async read(sandboxId, filePath) {
4583
- const res = await apiRequest(
4584
- this.options,
4723
+ const res = await this.request(
4585
4724
  "GET",
4586
- `/api/public/benchmark-containers/sandboxes/${sid(sandboxId)}/file?path=${encodeURIComponent(filePath)}`
4725
+ `${SANDBOXES}/${sid(sandboxId)}/file?path=${encodeURIComponent(filePath)}`
4587
4726
  );
4588
4727
  return { path: res.path, size: res.size, bytes: Buffer.from(res.contentBase64, "base64") };
4589
4728
  }
4590
4729
  write(sandboxId, filePath, bytes) {
4591
- return apiRequest(this.options, "PUT", `/api/public/benchmark-containers/sandboxes/${sid(sandboxId)}/file`, {
4730
+ return this.request("PUT", `${SANDBOXES}/${sid(sandboxId)}/file`, {
4592
4731
  path: filePath,
4593
4732
  contentBase64: bytes.toString("base64")
4594
4733
  });
4595
4734
  }
4596
4735
  exec(sandboxId, input) {
4597
- return apiRequest(this.options, "POST", `/api/public/benchmark-containers/sandboxes/${sid(sandboxId)}/exec`, input);
4736
+ return this.request("POST", `${SANDBOXES}/${sid(sandboxId)}/exec`, input);
4598
4737
  }
4599
4738
  check(sandboxId) {
4600
- return apiRequest(this.options, "POST", `/api/public/benchmark-containers/sandboxes/${sid(sandboxId)}/check`, {});
4739
+ return this.request("POST", `${SANDBOXES}/${sid(sandboxId)}/check`, {});
4601
4740
  }
4741
+ /** With `rebase`, a moved base is replayed onto; a 409 then names the conflicting paths (`rebaseConflicts`). */
4602
4742
  commit(sandboxId, input) {
4603
- return apiRequest(this.options, "POST", `/api/public/benchmark-containers/sandboxes/${sid(sandboxId)}/commit`, input);
4743
+ const { rebase, ...rest } = input;
4744
+ return this.request("POST", `${SANDBOXES}/${sid(sandboxId)}/commit`, rebase ? { ...rest, rebase: true } : rest);
4604
4745
  }
4605
4746
  /**
4606
4747
  * A rows file already in the sandbox tree into the PLATFORM world the
@@ -4609,10 +4750,11 @@ var init_sandbox = __esm({
4609
4750
  * tree and never carries data.
4610
4751
  */
4611
4752
  importData(sandboxId, input) {
4612
- return apiRequest(this.options, "POST", `/api/public/benchmark-containers/sandboxes/${sid(sandboxId)}/import`, input);
4753
+ return this.request("POST", `${SANDBOXES}/${sid(sandboxId)}/import`, input);
4613
4754
  }
4614
- close(sandboxId) {
4615
- return apiRequest(this.options, "DELETE", `/api/public/benchmark-containers/sandboxes/${sid(sandboxId)}`);
4755
+ /** Uncommitted work is a 409 (`uncommittedPaths`) unless `force` discards it. */
4756
+ close(sandboxId, opts = {}) {
4757
+ return this.request("DELETE", `${SANDBOXES}/${sid(sandboxId)}`, opts.force ? { force: true } : void 0);
4616
4758
  }
4617
4759
  };
4618
4760
  }
@@ -5141,42 +5283,12 @@ var init_router = __esm({
5141
5283
  });
5142
5284
 
5143
5285
  // src/cli/config.ts
5144
- function transportDetail(error, timeoutMs) {
5145
- if (error instanceof Error && error.name === "AbortError") return `timed out after ${Math.round(timeoutMs / 1e3)}s`;
5146
- const cause = error instanceof Error && error.cause instanceof Error ? error.cause : void 0;
5147
- const code = cause && "code" in cause && typeof cause.code === "string" ? `${cause.code}: ` : "";
5148
- const message = cause?.message ?? (error instanceof Error ? error.message : String(error));
5149
- return `${code}${message}`;
5150
- }
5151
5286
  async function api(creds, method, route, body, init2 = {}) {
5152
- const controller = new AbortController();
5153
- const timeoutMs = init2.timeoutMs ?? 12e4;
5154
- const timer = setTimeout(() => controller.abort(), timeoutMs);
5155
- let res;
5156
- try {
5157
- res = await fetch(`${creds.host}${route}`, {
5158
- method,
5159
- headers: {
5160
- "content-type": "application/json",
5161
- accept: "application/json",
5162
- authorization: "Basic " + Buffer.from(`${creds.publicKey}:${creds.secretKey}`).toString("base64")
5163
- },
5164
- ...body === void 0 ? {} : { body: JSON.stringify(body) },
5165
- signal: controller.signal
5166
- });
5167
- } catch (error) {
5168
- clearTimeout(timer);
5169
- throw new UnreachableError(creds.host, method, route, transportDetail(error, timeoutMs));
5170
- }
5171
- try {
5172
- const text2 = await res.text();
5173
- if (!res.ok) throw new ApiError(res.status, method, route, text2);
5174
- return text2 ? JSON.parse(text2) : {};
5175
- } finally {
5176
- clearTimeout(timer);
5177
- }
5287
+ const reply = await new PlatformTransport(creds).send(method, route, body, init2);
5288
+ if (!reply.ok) throw new ApiError2(reply.status, method, route, reply.text);
5289
+ return reply.text ? JSON.parse(reply.text) : {};
5178
5290
  }
5179
- var fs6, os, path6, ApiError, UnreachableError;
5291
+ var fs6, os, path6, ApiError2;
5180
5292
  var init_config = __esm({
5181
5293
  "src/cli/config.ts"() {
5182
5294
  "use strict";
@@ -5185,7 +5297,8 @@ var init_config = __esm({
5185
5297
  path6 = __toESM(require("path"));
5186
5298
  init_router();
5187
5299
  init_worlds();
5188
- ApiError = class extends CliError {
5300
+ init_transport();
5301
+ ApiError2 = class extends CliError {
5189
5302
  constructor(status, method, route, text2) {
5190
5303
  const body = parseErrorBody(text2);
5191
5304
  super(`${method} ${route} -> ${status}: ${body.detail}`, 1);
@@ -5201,19 +5314,6 @@ var init_config = __esm({
5201
5314
  text;
5202
5315
  code;
5203
5316
  };
5204
- UnreachableError = class extends CliError {
5205
- constructor(host, method, route, detail) {
5206
- super(`${method} ${route}: no answer from ${host} (${detail}). Check the host and the network, then retry.`, 1);
5207
- this.host = host;
5208
- this.method = method;
5209
- this.route = route;
5210
- this.detail = detail;
5211
- }
5212
- host;
5213
- method;
5214
- route;
5215
- detail;
5216
- };
5217
5317
  }
5218
5318
  });
5219
5319
 
@@ -5392,7 +5492,7 @@ var init_local = __esm({
5392
5492
  path7 = __toESM(require("path"));
5393
5493
  init_router();
5394
5494
  init_config();
5395
- MIN_PYTHON = [3, 11];
5495
+ MIN_PYTHON = [3, 12];
5396
5496
  DIAGNOSTIC_TAIL = 600;
5397
5497
  BRIDGE_BOOTSTRAP = `import sys,runpy,types,os
5398
5498
  root=sys.argv[1]
@@ -5404,7 +5504,6 @@ runpy.run_module('gatewaysdk.environment.schema.platform',run_name='__main__')`;
5404
5504
  PYTHON_CANDIDATES = [
5405
5505
  "python3.13",
5406
5506
  "python3.12",
5407
- "python3.11",
5408
5507
  "python3",
5409
5508
  "python"
5410
5509
  ];
@@ -5514,47 +5613,33 @@ function runsLocally(request) {
5514
5613
  async function runtime(creds, request, opts = {}) {
5515
5614
  const local = localRuntime();
5516
5615
  if (local && runsLocally(request)) {
5517
- const payload = await localBridge(request, local, opts);
5518
- const detail = detailFrom(payload);
5519
- if (detail) throw new BridgeRejected(detail);
5520
- return payload;
5616
+ const payload2 = await localBridge(request, local, opts);
5617
+ const detail2 = detailFrom(payload2);
5618
+ if (detail2) throw new BridgeRejected(detail2);
5619
+ return payload2;
5521
5620
  }
5522
5621
  if (!creds)
5523
5622
  throw new CliError(
5524
5623
  "This needs the schema runtime (the CLI bundles it) or platform credentials (`gateway auth login`). " + localRuntimeReason()
5525
5624
  );
5526
- const controller = new AbortController();
5527
- const timer = setTimeout(() => controller.abort(), opts.timeoutMs ?? 18e4);
5528
5625
  const route = "/api/public/worlds/runtime";
5626
+ const res = await new PlatformTransport(creds).send("POST", route, request, {
5627
+ timeoutMs: opts.timeoutMs ?? RUNTIME_TIMEOUT_MS
5628
+ });
5629
+ let payload = null;
5529
5630
  try {
5530
- const res = await fetch(`${creds.host}${route}`, {
5531
- method: "POST",
5532
- headers: {
5533
- "content-type": "application/json",
5534
- accept: "application/json",
5535
- authorization: "Basic " + Buffer.from(`${creds.publicKey}:${creds.secretKey}`).toString("base64")
5536
- },
5537
- body: JSON.stringify(request),
5538
- signal: controller.signal
5539
- });
5540
- const text2 = await res.text();
5541
- let payload = null;
5542
- try {
5543
- payload = text2 ? JSON.parse(text2) : {};
5544
- } catch {
5545
- payload = null;
5546
- }
5547
- const detail = detailFrom(payload);
5548
- if (detail) throw new BridgeRejected(detail);
5549
- if (!res.ok)
5550
- throw new CliError(`POST ${route} (${request.command}) -> ${res.status}: ${text2.slice(0, 600)}`, 1);
5551
- if (payload === null) throw new CliError(`POST ${route} (${request.command}) returned non-JSON`, 1);
5552
- return payload;
5553
- } finally {
5554
- clearTimeout(timer);
5631
+ payload = res.text ? JSON.parse(res.text) : {};
5632
+ } catch {
5633
+ payload = null;
5555
5634
  }
5635
+ const detail = detailFrom(payload);
5636
+ if (detail) throw new BridgeRejected(detail);
5637
+ if (!res.ok)
5638
+ throw new CliError(`POST ${route} (${request.command}) -> ${res.status}: ${res.text.slice(0, 600)}`, 1);
5639
+ if (payload === null) throw new CliError(`POST ${route} (${request.command}) returned non-JSON`, 1);
5640
+ return payload;
5556
5641
  }
5557
- var fs8, path8, MAX_WORLD_FILES, SKIP_DIRS, BUILD_OUTPUT, BridgeRejected, YAML_NAME;
5642
+ var fs8, path8, MAX_WORLD_FILES, RUNTIME_TIMEOUT_MS, SKIP_DIRS, BUILD_OUTPUT, BridgeRejected, YAML_NAME;
5558
5643
  var init_client = __esm({
5559
5644
  "src/cli/runtime/client.ts"() {
5560
5645
  "use strict";
@@ -5562,7 +5647,9 @@ var init_client = __esm({
5562
5647
  path8 = __toESM(require("path"));
5563
5648
  init_router();
5564
5649
  init_local();
5650
+ init_transport();
5565
5651
  MAX_WORLD_FILES = 2e3;
5652
+ RUNTIME_TIMEOUT_MS = 18e4;
5566
5653
  SKIP_DIRS = /* @__PURE__ */ new Set(["__pycache__", ".git", "node_modules", ".gateway"]);
5567
5654
  BUILD_OUTPUT = /(^|\/)state\.(sqlite|json)$/;
5568
5655
  BridgeRejected = class extends CliError {
@@ -6695,7 +6782,7 @@ var init_dryRun = __esm({
6695
6782
  // src/worlds/index.ts
6696
6783
  var worlds_exports = {};
6697
6784
  __export(worlds_exports, {
6698
- ApiError: () => ApiError2,
6785
+ ApiError: () => ApiError,
6699
6786
  BROWSER_GONE_PATTERNS: () => BROWSER_GONE_PATTERNS,
6700
6787
  BROWSER_TIERS: () => BROWSER_TIERS,
6701
6788
  BrowserActionRecorder: () => BrowserActionRecorder,
@@ -6721,8 +6808,12 @@ __export(worlds_exports, {
6721
6808
  HostedDryRunClient: () => HostedDryRunClient,
6722
6809
  IDLE_WARNING_MINUTES: () => IDLE_WARNING_MINUTES,
6723
6810
  NO_GRADER_REASON: () => NO_GRADER_REASON,
6811
+ PLATFORM_TIMEOUT_DEFAULT_MS: () => PLATFORM_TIMEOUT_DEFAULT_MS,
6812
+ PLATFORM_TIMEOUT_ENV: () => PLATFORM_TIMEOUT_ENV,
6813
+ PlatformTransport: () => PlatformTransport,
6724
6814
  PushSlugConflict: () => PushSlugConflict,
6725
6815
  RECOVER_BUDGET_MS: () => RECOVER_BUDGET_MS,
6816
+ SANDBOX_REQUEST_TIMEOUT_MS: () => SANDBOX_REQUEST_TIMEOUT_MS,
6726
6817
  SESSION_STATES: () => SESSION_STATES,
6727
6818
  STATUS_WAIT_CAP_SECONDS: () => STATUS_WAIT_CAP_SECONDS,
6728
6819
  STRIP_PREFIX: () => STRIP_PREFIX,
@@ -6731,6 +6822,8 @@ __export(worlds_exports, {
6731
6822
  TRANSFORMS: () => TRANSFORMS,
6732
6823
  TaskRun: () => TaskRun,
6733
6824
  TaskSessions: () => TaskSessions,
6825
+ TransportCause: () => TransportCause,
6826
+ UnreachableError: () => UnreachableError,
6734
6827
  VERIFIER_REWARD_PREFIX: () => VERIFIER_REWARD_PREFIX,
6735
6828
  WHITESPACE: () => WHITESPACE,
6736
6829
  WorldBrowser: () => WorldBrowser,
@@ -6798,6 +6891,7 @@ __export(worlds_exports, {
6798
6891
  parseToolCallRecord: () => parseToolCallRecord,
6799
6892
  parseTransform: () => parseTransform,
6800
6893
  parseWorldTaskRefs: () => parseWorldTaskRefs,
6894
+ platformTimeoutMs: () => platformTimeoutMs,
6801
6895
  preserveForm: () => preserveForm,
6802
6896
  propose: () => propose,
6803
6897
  pull: () => pull,
@@ -6809,6 +6903,7 @@ __export(worlds_exports, {
6809
6903
  queryRowsSearch: () => queryRowsSearch,
6810
6904
  readLocalMeta: () => readLocalMeta,
6811
6905
  readToolCallRecords: () => readToolCallRecords,
6906
+ rebaseConflicts: () => rebaseConflicts,
6812
6907
  redactActionArgs: () => redactActionArgs,
6813
6908
  redactionOf: () => redactionOf,
6814
6909
  releaseConnection: () => releaseConnection,
@@ -6831,6 +6926,7 @@ __export(worlds_exports, {
6831
6926
  toolCallsFromObservations: () => toolCallsFromObservations,
6832
6927
  uiEntryUrl: () => uiEntryUrl,
6833
6928
  uiUrl: () => uiUrl,
6929
+ uncommittedPaths: () => uncommittedPaths,
6834
6930
  updateTask: () => updateTask,
6835
6931
  upsertRunConfig: () => upsertRunConfig,
6836
6932
  validateTask: () => validateTask,
@@ -6870,19 +6966,10 @@ function parseErrorBody(text2, limit = 600) {
6870
6966
  code: stableCode
6871
6967
  };
6872
6968
  }
6873
- async function apiRequest(options, method, path12, body) {
6874
- const { host, publicKey, secretKey } = resolveEnv(options);
6875
- const res = await fetch(`${host}${path12}`, {
6876
- method,
6877
- headers: {
6878
- "content-type": "application/json",
6879
- authorization: "Basic " + Buffer.from(`${publicKey}:${secretKey}`).toString("base64")
6880
- },
6881
- ...body === void 0 ? {} : { body: JSON.stringify(body) }
6882
- });
6883
- const text2 = await res.text();
6884
- if (!res.ok) throw new ApiError2(res.status, method, path12, text2);
6885
- return JSON.parse(text2);
6969
+ async function apiRequest(options, method, path12, body, init2 = {}) {
6970
+ const reply = await new PlatformTransport(resolveEnv(options)).send(method, path12, body, init2);
6971
+ if (!reply.ok) throw new ApiError(reply.status, method, path12, reply.text);
6972
+ return JSON.parse(reply.text);
6886
6973
  }
6887
6974
  async function setEnvSecret(slug, key, value, options = {}) {
6888
6975
  return apiRequest(
@@ -7058,9 +7145,11 @@ async function resolveWorld(slugRef, slug, ref, pin, options) {
7058
7145
  }
7059
7146
  return world;
7060
7147
  }
7061
- var ApiError2, WorldTask, WorldSet;
7148
+ var ApiError, WorldTask, WorldSet;
7062
7149
  var init_worlds = __esm({
7063
7150
  "src/worlds/index.ts"() {
7151
+ init_transport();
7152
+ init_transport();
7064
7153
  init_session();
7065
7154
  init_sessionList();
7066
7155
  init_sessionContract();
@@ -7084,15 +7173,17 @@ var init_worlds = __esm({
7084
7173
  init_sandbox();
7085
7174
  init_editSessions();
7086
7175
  init_dryRun();
7087
- ApiError2 = class extends Error {
7088
- constructor(status, method, path12, body) {
7089
- const parsed = parseErrorBody(body);
7176
+ ApiError = class extends Error {
7177
+ constructor(status, method, path12, text2) {
7178
+ const parsed = parseErrorBody(text2);
7090
7179
  super(`${method} ${path12} -> ${status}: ${parsed.detail}`);
7091
7180
  this.status = status;
7181
+ this.text = text2;
7092
7182
  this.name = "ApiError";
7093
7183
  this.code = parsed.code;
7094
7184
  }
7095
7185
  status;
7186
+ text;
7096
7187
  code;
7097
7188
  };
7098
7189
  WorldTask = class {
@@ -7198,8 +7289,12 @@ init_worlds();
7198
7289
  HostedDryRunClient,
7199
7290
  IDLE_WARNING_MINUTES,
7200
7291
  NO_GRADER_REASON,
7292
+ PLATFORM_TIMEOUT_DEFAULT_MS,
7293
+ PLATFORM_TIMEOUT_ENV,
7294
+ PlatformTransport,
7201
7295
  PushSlugConflict,
7202
7296
  RECOVER_BUDGET_MS,
7297
+ SANDBOX_REQUEST_TIMEOUT_MS,
7203
7298
  SESSION_STATES,
7204
7299
  STATUS_WAIT_CAP_SECONDS,
7205
7300
  STRIP_PREFIX,
@@ -7208,6 +7303,8 @@ init_worlds();
7208
7303
  TRANSFORMS,
7209
7304
  TaskRun,
7210
7305
  TaskSessions,
7306
+ TransportCause,
7307
+ UnreachableError,
7211
7308
  VERIFIER_REWARD_PREFIX,
7212
7309
  WHITESPACE,
7213
7310
  WorldBrowser,
@@ -7275,6 +7372,7 @@ init_worlds();
7275
7372
  parseToolCallRecord,
7276
7373
  parseTransform,
7277
7374
  parseWorldTaskRefs,
7375
+ platformTimeoutMs,
7278
7376
  preserveForm,
7279
7377
  propose,
7280
7378
  pull,
@@ -7286,6 +7384,7 @@ init_worlds();
7286
7384
  queryRowsSearch,
7287
7385
  readLocalMeta,
7288
7386
  readToolCallRecords,
7387
+ rebaseConflicts,
7289
7388
  redactActionArgs,
7290
7389
  redactionOf,
7291
7390
  releaseConnection,
@@ -7308,6 +7407,7 @@ init_worlds();
7308
7407
  toolCallsFromObservations,
7309
7408
  uiEntryUrl,
7310
7409
  uiUrl,
7410
+ uncommittedPaths,
7311
7411
  updateTask,
7312
7412
  upsertRunConfig,
7313
7413
  validateTask,