@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
package/dist/index.js CHANGED
@@ -464,6 +464,115 @@ var init_scores = __esm({
464
464
  }
465
465
  });
466
466
 
467
+ // src/worlds/transport.ts
468
+ function platformTimeoutMs(env = process.env) {
469
+ const raw = env[PLATFORM_TIMEOUT_ENV];
470
+ if (raw === void 0 || raw === "") return PLATFORM_TIMEOUT_DEFAULT_MS;
471
+ const value = Number(raw);
472
+ if (Number.isInteger(value) && value > 0) return value;
473
+ throw new Error(`${PLATFORM_TIMEOUT_ENV} must be a positive whole number of milliseconds, not \`${raw}\`.`);
474
+ }
475
+ var PLATFORM_TIMEOUT_ENV, PLATFORM_TIMEOUT_DEFAULT_MS, CHECK_HOST, RETRY, CAUSES, UNKNOWN_CAUSE, TransportCause, UnreachableError, PlatformTransport;
476
+ var init_transport = __esm({
477
+ "src/worlds/transport.ts"() {
478
+ "use strict";
479
+ PLATFORM_TIMEOUT_ENV = "GATEWAY_TIMEOUT_MS";
480
+ PLATFORM_TIMEOUT_DEFAULT_MS = 12e4;
481
+ CHECK_HOST = "Check GATEWAY_HOST (or --host) points at a running platform, then retry.";
482
+ RETRY = "Retry; if it repeats, check the network between here and the platform.";
483
+ CAUSES = {
484
+ ECONNREFUSED: { reason: "connection refused", next: CHECK_HOST },
485
+ ENOTFOUND: { reason: "DNS lookup failed", next: CHECK_HOST },
486
+ EAI_AGAIN: { reason: "DNS lookup failed", next: CHECK_HOST },
487
+ ETIMEDOUT: { reason: "connect timed out", next: CHECK_HOST },
488
+ UND_ERR_CONNECT_TIMEOUT: { reason: "connect timed out", next: CHECK_HOST },
489
+ EHOSTUNREACH: { reason: "host unreachable", next: CHECK_HOST },
490
+ ENETUNREACH: { reason: "network unreachable", next: RETRY },
491
+ ECONNRESET: { reason: "connection dropped", next: RETRY },
492
+ UND_ERR_SOCKET: { reason: "connection dropped", next: RETRY },
493
+ EPIPE: { reason: "connection dropped", next: RETRY }
494
+ };
495
+ UNKNOWN_CAUSE = { reason: "network error", next: CHECK_HOST };
496
+ TransportCause = class _TransportCause {
497
+ constructor(reason, detail, next) {
498
+ this.reason = reason;
499
+ this.detail = detail;
500
+ this.next = next;
501
+ }
502
+ reason;
503
+ detail;
504
+ next;
505
+ static timeout(timeoutMs) {
506
+ return new _TransportCause(
507
+ `timed out after ${timeoutMs / 1e3}s`,
508
+ null,
509
+ `Retry; if the platform is slow, raise ${PLATFORM_TIMEOUT_ENV} (milliseconds per request).`
510
+ );
511
+ }
512
+ static of(error) {
513
+ const cause = error instanceof Error && error.cause instanceof Error ? error.cause : void 0;
514
+ const code = cause && "code" in cause && typeof cause.code === "string" ? cause.code : null;
515
+ const message = cause?.message ?? (error instanceof Error ? error.message : String(error));
516
+ const known = code && CAUSES[code] || UNKNOWN_CAUSE;
517
+ return new _TransportCause(known.reason, code ? `${code}: ${message}` : message, known.next);
518
+ }
519
+ describe() {
520
+ return this.detail === null ? this.reason : `${this.reason} (${this.detail})`;
521
+ }
522
+ };
523
+ UnreachableError = class extends Error {
524
+ constructor(host, method, route, failure) {
525
+ super(`${method} ${route}: no answer from ${host}: ${failure.describe()}. ${failure.next}`);
526
+ this.host = host;
527
+ this.method = method;
528
+ this.route = route;
529
+ this.failure = failure;
530
+ this.name = "UnreachableError";
531
+ }
532
+ host;
533
+ method;
534
+ route;
535
+ failure;
536
+ };
537
+ PlatformTransport = class {
538
+ constructor(endpoint, timeoutMs = platformTimeoutMs()) {
539
+ this.endpoint = endpoint;
540
+ this.timeoutMs = timeoutMs;
541
+ }
542
+ endpoint;
543
+ timeoutMs;
544
+ /** A request that legitimately takes longer (a sandbox exec, a world create) waits its own budget; every other one waits the default. */
545
+ budget(ownMs) {
546
+ return Math.max(ownMs ?? 0, this.timeoutMs);
547
+ }
548
+ async send(method, route, body, opts = {}) {
549
+ const timeoutMs = this.budget(opts.timeoutMs);
550
+ const payload = body === void 0 ? {} : { body: JSON.stringify(body) };
551
+ const controller = new AbortController();
552
+ const timer = setTimeout(() => controller.abort(), timeoutMs);
553
+ try {
554
+ const res = await fetch(`${this.endpoint.host}${route}`, {
555
+ method,
556
+ headers: {
557
+ "content-type": "application/json",
558
+ accept: "application/json",
559
+ authorization: "Basic " + Buffer.from(`${this.endpoint.publicKey}:${this.endpoint.secretKey}`).toString("base64")
560
+ },
561
+ ...payload,
562
+ signal: controller.signal
563
+ });
564
+ return { status: res.status, ok: res.ok, text: await res.text() };
565
+ } catch (error) {
566
+ const cause = controller.signal.aborted ? TransportCause.timeout(timeoutMs) : TransportCause.of(error);
567
+ throw new UnreachableError(this.endpoint.host, method, route, cause);
568
+ } finally {
569
+ clearTimeout(timer);
570
+ }
571
+ }
572
+ };
573
+ }
574
+ });
575
+
467
576
  // src/worlds/browserReconnect.ts
468
577
  async function closeConnection(c) {
469
578
  await c.context.close();
@@ -2472,7 +2581,7 @@ var require_package = __commonJS({
2472
2581
  "package.json"(exports2, module2) {
2473
2582
  module2.exports = {
2474
2583
  name: "@withgateway/sdk",
2475
- version: "0.2.8",
2584
+ version: "0.2.9",
2476
2585
  description: "Gateway SDK for TypeScript - A/B experiments, tracing, and observability",
2477
2586
  main: "./dist/index.js",
2478
2587
  module: "./dist/index.mjs",
@@ -4664,6 +4773,34 @@ function parseSlugRef(slugRef) {
4664
4773
  if (at === -1) return { slug: slugRef };
4665
4774
  return { slug: slugRef.slice(0, at), ref: slugRef.slice(at + 1) };
4666
4775
  }
4776
+ function rebaseConflicts(error) {
4777
+ if (!(error instanceof ApiError) || error.status !== 409) return null;
4778
+ let body;
4779
+ try {
4780
+ body = JSON.parse(error.text);
4781
+ } catch {
4782
+ return null;
4783
+ }
4784
+ const conflicts = body?.conflicts;
4785
+ if (!Array.isArray(conflicts)) return null;
4786
+ return conflicts.filter(isConflictPath).map(({ path: path16, reason }) => ({ path: path16, reason }));
4787
+ }
4788
+ function isConflictPath(value) {
4789
+ const entry = value;
4790
+ return typeof entry?.path === "string" && typeof entry.reason === "string";
4791
+ }
4792
+ function uncommittedPaths(error) {
4793
+ if (!(error instanceof ApiError) || error.status !== 409 || error.code !== "sandbox_uncommitted") return null;
4794
+ let body;
4795
+ try {
4796
+ body = JSON.parse(error.text);
4797
+ } catch {
4798
+ return null;
4799
+ }
4800
+ const uncommitted = body?.uncommitted;
4801
+ if (!Array.isArray(uncommitted)) return null;
4802
+ return uncommitted.filter((p) => typeof p === "string");
4803
+ }
4667
4804
  function listQuery(filter) {
4668
4805
  const params = new URLSearchParams();
4669
4806
  if (filter.status) params.set("status", filter.status);
@@ -4672,18 +4809,25 @@ function listQuery(filter) {
4672
4809
  const qs3 = params.toString();
4673
4810
  return qs3 ? `?${qs3}` : "";
4674
4811
  }
4675
- var isSandboxImportPending, sid, WorldSandboxClient;
4812
+ var isSandboxImportPending, sid, SANDBOXES, SANDBOX_REQUEST_TIMEOUT_MS, WorldSandboxClient;
4676
4813
  var init_sandbox = __esm({
4677
4814
  "src/worlds/sandbox.ts"() {
4678
4815
  "use strict";
4679
4816
  init_worlds();
4680
4817
  isSandboxImportPending = (answer) => !("versionId" in answer);
4681
4818
  sid = encodeURIComponent;
4819
+ SANDBOXES = "/api/public/benchmark-containers/sandboxes";
4820
+ SANDBOX_REQUEST_TIMEOUT_MS = 66e4;
4682
4821
  WorldSandboxClient = class {
4683
4822
  constructor(options = {}) {
4684
4823
  this.options = options;
4685
4824
  }
4686
4825
  options;
4826
+ request(method, path16, body) {
4827
+ return apiRequest(this.options, method, path16, body, {
4828
+ timeoutMs: SANDBOX_REQUEST_TIMEOUT_MS
4829
+ });
4830
+ }
4687
4831
  /**
4688
4832
  * `{ slug, ref? }` opens a READY version; `{ new, from }` opens a sandbox on
4689
4833
  * a world that does not exist yet (409 `world_exists` if the slug is taken,
@@ -4691,42 +4835,39 @@ var init_sandbox = __esm({
4691
4835
  * creates the world on `main`.
4692
4836
  */
4693
4837
  open(target) {
4694
- return apiRequest(this.options, "POST", "/api/public/benchmark-containers/sandboxes", target);
4838
+ return this.request("POST", `${SANDBOXES}`, target);
4695
4839
  }
4696
4840
  status(sandboxId) {
4697
- return apiRequest(this.options, "GET", `/api/public/benchmark-containers/sandboxes/${sid(sandboxId)}`);
4841
+ return this.request("GET", `${SANDBOXES}/${sid(sandboxId)}`);
4698
4842
  }
4699
4843
  /** The project's sandboxes, newest first — how an agent finds one it left open. */
4700
4844
  async list(filter = {}) {
4701
- const res = await apiRequest(
4702
- this.options,
4703
- "GET",
4704
- `/api/public/benchmark-containers/sandboxes${listQuery(filter)}`
4705
- );
4845
+ const res = await this.request("GET", `${SANDBOXES}${listQuery(filter)}`);
4706
4846
  return res.sandboxes;
4707
4847
  }
4708
4848
  async read(sandboxId, filePath) {
4709
- const res = await apiRequest(
4710
- this.options,
4849
+ const res = await this.request(
4711
4850
  "GET",
4712
- `/api/public/benchmark-containers/sandboxes/${sid(sandboxId)}/file?path=${encodeURIComponent(filePath)}`
4851
+ `${SANDBOXES}/${sid(sandboxId)}/file?path=${encodeURIComponent(filePath)}`
4713
4852
  );
4714
4853
  return { path: res.path, size: res.size, bytes: Buffer.from(res.contentBase64, "base64") };
4715
4854
  }
4716
4855
  write(sandboxId, filePath, bytes) {
4717
- return apiRequest(this.options, "PUT", `/api/public/benchmark-containers/sandboxes/${sid(sandboxId)}/file`, {
4856
+ return this.request("PUT", `${SANDBOXES}/${sid(sandboxId)}/file`, {
4718
4857
  path: filePath,
4719
4858
  contentBase64: bytes.toString("base64")
4720
4859
  });
4721
4860
  }
4722
4861
  exec(sandboxId, input) {
4723
- return apiRequest(this.options, "POST", `/api/public/benchmark-containers/sandboxes/${sid(sandboxId)}/exec`, input);
4862
+ return this.request("POST", `${SANDBOXES}/${sid(sandboxId)}/exec`, input);
4724
4863
  }
4725
4864
  check(sandboxId) {
4726
- return apiRequest(this.options, "POST", `/api/public/benchmark-containers/sandboxes/${sid(sandboxId)}/check`, {});
4865
+ return this.request("POST", `${SANDBOXES}/${sid(sandboxId)}/check`, {});
4727
4866
  }
4867
+ /** With `rebase`, a moved base is replayed onto; a 409 then names the conflicting paths (`rebaseConflicts`). */
4728
4868
  commit(sandboxId, input) {
4729
- return apiRequest(this.options, "POST", `/api/public/benchmark-containers/sandboxes/${sid(sandboxId)}/commit`, input);
4869
+ const { rebase, ...rest } = input;
4870
+ return this.request("POST", `${SANDBOXES}/${sid(sandboxId)}/commit`, rebase ? { ...rest, rebase: true } : rest);
4730
4871
  }
4731
4872
  /**
4732
4873
  * A rows file already in the sandbox tree into the PLATFORM world the
@@ -4735,10 +4876,11 @@ var init_sandbox = __esm({
4735
4876
  * tree and never carries data.
4736
4877
  */
4737
4878
  importData(sandboxId, input) {
4738
- return apiRequest(this.options, "POST", `/api/public/benchmark-containers/sandboxes/${sid(sandboxId)}/import`, input);
4879
+ return this.request("POST", `${SANDBOXES}/${sid(sandboxId)}/import`, input);
4739
4880
  }
4740
- close(sandboxId) {
4741
- return apiRequest(this.options, "DELETE", `/api/public/benchmark-containers/sandboxes/${sid(sandboxId)}`);
4881
+ /** Uncommitted work is a 409 (`uncommittedPaths`) unless `force` discards it. */
4882
+ close(sandboxId, opts = {}) {
4883
+ return this.request("DELETE", `${SANDBOXES}/${sid(sandboxId)}`, opts.force ? { force: true } : void 0);
4742
4884
  }
4743
4885
  };
4744
4886
  }
@@ -5267,42 +5409,12 @@ var init_router = __esm({
5267
5409
  });
5268
5410
 
5269
5411
  // src/cli/config.ts
5270
- function transportDetail(error, timeoutMs) {
5271
- if (error instanceof Error && error.name === "AbortError") return `timed out after ${Math.round(timeoutMs / 1e3)}s`;
5272
- const cause = error instanceof Error && error.cause instanceof Error ? error.cause : void 0;
5273
- const code = cause && "code" in cause && typeof cause.code === "string" ? `${cause.code}: ` : "";
5274
- const message = cause?.message ?? (error instanceof Error ? error.message : String(error));
5275
- return `${code}${message}`;
5276
- }
5277
5412
  async function api(creds, method, route, body, init3 = {}) {
5278
- const controller = new AbortController();
5279
- const timeoutMs = init3.timeoutMs ?? 12e4;
5280
- const timer = setTimeout(() => controller.abort(), timeoutMs);
5281
- let res;
5282
- try {
5283
- res = await fetch(`${creds.host}${route}`, {
5284
- method,
5285
- headers: {
5286
- "content-type": "application/json",
5287
- accept: "application/json",
5288
- authorization: "Basic " + Buffer.from(`${creds.publicKey}:${creds.secretKey}`).toString("base64")
5289
- },
5290
- ...body === void 0 ? {} : { body: JSON.stringify(body) },
5291
- signal: controller.signal
5292
- });
5293
- } catch (error) {
5294
- clearTimeout(timer);
5295
- throw new UnreachableError(creds.host, method, route, transportDetail(error, timeoutMs));
5296
- }
5297
- try {
5298
- const text2 = await res.text();
5299
- if (!res.ok) throw new ApiError(res.status, method, route, text2);
5300
- return text2 ? JSON.parse(text2) : {};
5301
- } finally {
5302
- clearTimeout(timer);
5303
- }
5413
+ const reply = await new PlatformTransport(creds).send(method, route, body, init3);
5414
+ if (!reply.ok) throw new ApiError2(reply.status, method, route, reply.text);
5415
+ return reply.text ? JSON.parse(reply.text) : {};
5304
5416
  }
5305
- var fs6, os, path6, ApiError, UnreachableError;
5417
+ var fs6, os, path6, ApiError2;
5306
5418
  var init_config = __esm({
5307
5419
  "src/cli/config.ts"() {
5308
5420
  "use strict";
@@ -5311,7 +5423,8 @@ var init_config = __esm({
5311
5423
  path6 = __toESM(require("path"));
5312
5424
  init_router();
5313
5425
  init_worlds();
5314
- ApiError = class extends CliError {
5426
+ init_transport();
5427
+ ApiError2 = class extends CliError {
5315
5428
  constructor(status, method, route, text2) {
5316
5429
  const body = parseErrorBody(text2);
5317
5430
  super(`${method} ${route} -> ${status}: ${body.detail}`, 1);
@@ -5327,19 +5440,6 @@ var init_config = __esm({
5327
5440
  text;
5328
5441
  code;
5329
5442
  };
5330
- UnreachableError = class extends CliError {
5331
- constructor(host, method, route, detail) {
5332
- super(`${method} ${route}: no answer from ${host} (${detail}). Check the host and the network, then retry.`, 1);
5333
- this.host = host;
5334
- this.method = method;
5335
- this.route = route;
5336
- this.detail = detail;
5337
- }
5338
- host;
5339
- method;
5340
- route;
5341
- detail;
5342
- };
5343
5443
  }
5344
5444
  });
5345
5445
 
@@ -5518,7 +5618,7 @@ var init_local = __esm({
5518
5618
  path7 = __toESM(require("path"));
5519
5619
  init_router();
5520
5620
  init_config();
5521
- MIN_PYTHON = [3, 11];
5621
+ MIN_PYTHON = [3, 12];
5522
5622
  DIAGNOSTIC_TAIL = 600;
5523
5623
  BRIDGE_BOOTSTRAP = `import sys,runpy,types,os
5524
5624
  root=sys.argv[1]
@@ -5530,7 +5630,6 @@ runpy.run_module('gatewaysdk.environment.schema.platform',run_name='__main__')`;
5530
5630
  PYTHON_CANDIDATES = [
5531
5631
  "python3.13",
5532
5632
  "python3.12",
5533
- "python3.11",
5534
5633
  "python3",
5535
5634
  "python"
5536
5635
  ];
@@ -5640,47 +5739,33 @@ function runsLocally(request) {
5640
5739
  async function runtime(creds, request, opts = {}) {
5641
5740
  const local = localRuntime();
5642
5741
  if (local && runsLocally(request)) {
5643
- const payload = await localBridge(request, local, opts);
5644
- const detail = detailFrom(payload);
5645
- if (detail) throw new BridgeRejected(detail);
5646
- return payload;
5742
+ const payload2 = await localBridge(request, local, opts);
5743
+ const detail2 = detailFrom(payload2);
5744
+ if (detail2) throw new BridgeRejected(detail2);
5745
+ return payload2;
5647
5746
  }
5648
5747
  if (!creds)
5649
5748
  throw new CliError(
5650
5749
  "This needs the schema runtime (the CLI bundles it) or platform credentials (`gateway auth login`). " + localRuntimeReason()
5651
5750
  );
5652
- const controller = new AbortController();
5653
- const timer = setTimeout(() => controller.abort(), opts.timeoutMs ?? 18e4);
5654
5751
  const route = "/api/public/worlds/runtime";
5752
+ const res = await new PlatformTransport(creds).send("POST", route, request, {
5753
+ timeoutMs: opts.timeoutMs ?? RUNTIME_TIMEOUT_MS
5754
+ });
5755
+ let payload = null;
5655
5756
  try {
5656
- const res = await fetch(`${creds.host}${route}`, {
5657
- method: "POST",
5658
- headers: {
5659
- "content-type": "application/json",
5660
- accept: "application/json",
5661
- authorization: "Basic " + Buffer.from(`${creds.publicKey}:${creds.secretKey}`).toString("base64")
5662
- },
5663
- body: JSON.stringify(request),
5664
- signal: controller.signal
5665
- });
5666
- const text2 = await res.text();
5667
- let payload = null;
5668
- try {
5669
- payload = text2 ? JSON.parse(text2) : {};
5670
- } catch {
5671
- payload = null;
5672
- }
5673
- const detail = detailFrom(payload);
5674
- if (detail) throw new BridgeRejected(detail);
5675
- if (!res.ok)
5676
- throw new CliError(`POST ${route} (${request.command}) -> ${res.status}: ${text2.slice(0, 600)}`, 1);
5677
- if (payload === null) throw new CliError(`POST ${route} (${request.command}) returned non-JSON`, 1);
5678
- return payload;
5679
- } finally {
5680
- clearTimeout(timer);
5757
+ payload = res.text ? JSON.parse(res.text) : {};
5758
+ } catch {
5759
+ payload = null;
5681
5760
  }
5761
+ const detail = detailFrom(payload);
5762
+ if (detail) throw new BridgeRejected(detail);
5763
+ if (!res.ok)
5764
+ throw new CliError(`POST ${route} (${request.command}) -> ${res.status}: ${res.text.slice(0, 600)}`, 1);
5765
+ if (payload === null) throw new CliError(`POST ${route} (${request.command}) returned non-JSON`, 1);
5766
+ return payload;
5682
5767
  }
5683
- var fs8, path8, MAX_WORLD_FILES, SKIP_DIRS, BUILD_OUTPUT, BridgeRejected, YAML_NAME;
5768
+ var fs8, path8, MAX_WORLD_FILES, RUNTIME_TIMEOUT_MS, SKIP_DIRS, BUILD_OUTPUT, BridgeRejected, YAML_NAME;
5684
5769
  var init_client = __esm({
5685
5770
  "src/cli/runtime/client.ts"() {
5686
5771
  "use strict";
@@ -5688,7 +5773,9 @@ var init_client = __esm({
5688
5773
  path8 = __toESM(require("path"));
5689
5774
  init_router();
5690
5775
  init_local();
5776
+ init_transport();
5691
5777
  MAX_WORLD_FILES = 2e3;
5778
+ RUNTIME_TIMEOUT_MS = 18e4;
5692
5779
  SKIP_DIRS = /* @__PURE__ */ new Set(["__pycache__", ".git", "node_modules", ".gateway"]);
5693
5780
  BUILD_OUTPUT = /(^|\/)state\.(sqlite|json)$/;
5694
5781
  BridgeRejected = class extends CliError {
@@ -6821,7 +6908,7 @@ var init_dryRun = __esm({
6821
6908
  // src/worlds/index.ts
6822
6909
  var worlds_exports = {};
6823
6910
  __export(worlds_exports, {
6824
- ApiError: () => ApiError2,
6911
+ ApiError: () => ApiError,
6825
6912
  BROWSER_GONE_PATTERNS: () => BROWSER_GONE_PATTERNS,
6826
6913
  BROWSER_TIERS: () => BROWSER_TIERS,
6827
6914
  BrowserActionRecorder: () => BrowserActionRecorder,
@@ -6847,8 +6934,12 @@ __export(worlds_exports, {
6847
6934
  HostedDryRunClient: () => HostedDryRunClient,
6848
6935
  IDLE_WARNING_MINUTES: () => IDLE_WARNING_MINUTES,
6849
6936
  NO_GRADER_REASON: () => NO_GRADER_REASON,
6937
+ PLATFORM_TIMEOUT_DEFAULT_MS: () => PLATFORM_TIMEOUT_DEFAULT_MS,
6938
+ PLATFORM_TIMEOUT_ENV: () => PLATFORM_TIMEOUT_ENV,
6939
+ PlatformTransport: () => PlatformTransport,
6850
6940
  PushSlugConflict: () => PushSlugConflict,
6851
6941
  RECOVER_BUDGET_MS: () => RECOVER_BUDGET_MS,
6942
+ SANDBOX_REQUEST_TIMEOUT_MS: () => SANDBOX_REQUEST_TIMEOUT_MS,
6852
6943
  SESSION_STATES: () => SESSION_STATES,
6853
6944
  STATUS_WAIT_CAP_SECONDS: () => STATUS_WAIT_CAP_SECONDS,
6854
6945
  STRIP_PREFIX: () => STRIP_PREFIX,
@@ -6857,6 +6948,8 @@ __export(worlds_exports, {
6857
6948
  TRANSFORMS: () => TRANSFORMS,
6858
6949
  TaskRun: () => TaskRun,
6859
6950
  TaskSessions: () => TaskSessions,
6951
+ TransportCause: () => TransportCause,
6952
+ UnreachableError: () => UnreachableError,
6860
6953
  VERIFIER_REWARD_PREFIX: () => VERIFIER_REWARD_PREFIX,
6861
6954
  WHITESPACE: () => WHITESPACE,
6862
6955
  WorldBrowser: () => WorldBrowser,
@@ -6924,6 +7017,7 @@ __export(worlds_exports, {
6924
7017
  parseToolCallRecord: () => parseToolCallRecord,
6925
7018
  parseTransform: () => parseTransform,
6926
7019
  parseWorldTaskRefs: () => parseWorldTaskRefs,
7020
+ platformTimeoutMs: () => platformTimeoutMs,
6927
7021
  preserveForm: () => preserveForm,
6928
7022
  propose: () => propose,
6929
7023
  pull: () => pull,
@@ -6935,6 +7029,7 @@ __export(worlds_exports, {
6935
7029
  queryRowsSearch: () => queryRowsSearch,
6936
7030
  readLocalMeta: () => readLocalMeta,
6937
7031
  readToolCallRecords: () => readToolCallRecords,
7032
+ rebaseConflicts: () => rebaseConflicts,
6938
7033
  redactActionArgs: () => redactActionArgs,
6939
7034
  redactionOf: () => redactionOf,
6940
7035
  releaseConnection: () => releaseConnection,
@@ -6957,6 +7052,7 @@ __export(worlds_exports, {
6957
7052
  toolCallsFromObservations: () => toolCallsFromObservations,
6958
7053
  uiEntryUrl: () => uiEntryUrl,
6959
7054
  uiUrl: () => uiUrl,
7055
+ uncommittedPaths: () => uncommittedPaths,
6960
7056
  updateTask: () => updateTask,
6961
7057
  upsertRunConfig: () => upsertRunConfig,
6962
7058
  validateTask: () => validateTask,
@@ -6995,19 +7091,10 @@ function parseErrorBody(text2, limit = 600) {
6995
7091
  code: stableCode
6996
7092
  };
6997
7093
  }
6998
- async function apiRequest(options, method, path16, body) {
6999
- const { host, publicKey, secretKey } = resolveEnv(options);
7000
- const res = await fetch(`${host}${path16}`, {
7001
- method,
7002
- headers: {
7003
- "content-type": "application/json",
7004
- authorization: "Basic " + Buffer.from(`${publicKey}:${secretKey}`).toString("base64")
7005
- },
7006
- ...body === void 0 ? {} : { body: JSON.stringify(body) }
7007
- });
7008
- const text2 = await res.text();
7009
- if (!res.ok) throw new ApiError2(res.status, method, path16, text2);
7010
- return JSON.parse(text2);
7094
+ async function apiRequest(options, method, path16, body, init3 = {}) {
7095
+ const reply = await new PlatformTransport(resolveEnv(options)).send(method, path16, body, init3);
7096
+ if (!reply.ok) throw new ApiError(reply.status, method, path16, reply.text);
7097
+ return JSON.parse(reply.text);
7011
7098
  }
7012
7099
  async function setEnvSecret(slug, key2, value, options = {}) {
7013
7100
  return apiRequest(
@@ -7183,10 +7270,12 @@ async function resolveWorld(slugRef, slug, ref, pin, options) {
7183
7270
  }
7184
7271
  return world;
7185
7272
  }
7186
- var ApiError2, WorldTask, WorldSet;
7273
+ var ApiError, WorldTask, WorldSet;
7187
7274
  var init_worlds = __esm({
7188
7275
  "src/worlds/index.ts"() {
7189
7276
  "use strict";
7277
+ init_transport();
7278
+ init_transport();
7190
7279
  init_session();
7191
7280
  init_sessionList();
7192
7281
  init_sessionContract();
@@ -7210,15 +7299,17 @@ var init_worlds = __esm({
7210
7299
  init_sandbox();
7211
7300
  init_editSessions();
7212
7301
  init_dryRun();
7213
- ApiError2 = class extends Error {
7214
- constructor(status, method, path16, body) {
7215
- const parsed = parseErrorBody(body);
7302
+ ApiError = class extends Error {
7303
+ constructor(status, method, path16, text2) {
7304
+ const parsed = parseErrorBody(text2);
7216
7305
  super(`${method} ${path16} -> ${status}: ${parsed.detail}`);
7217
7306
  this.status = status;
7307
+ this.text = text2;
7218
7308
  this.name = "ApiError";
7219
7309
  this.code = parsed.code;
7220
7310
  }
7221
7311
  status;
7312
+ text;
7222
7313
  code;
7223
7314
  };
7224
7315
  WorldTask = class {
@@ -7300,7 +7391,7 @@ var init_worlds = __esm({
7300
7391
  var src_exports = {};
7301
7392
  __export(src_exports, {
7302
7393
  AGENT_ID_KEY: () => AGENT_ID_KEY,
7303
- ApiError: () => ApiError2,
7394
+ ApiError: () => ApiError,
7304
7395
  BROWSER_GONE_PATTERNS: () => BROWSER_GONE_PATTERNS,
7305
7396
  BROWSER_TIERS: () => BROWSER_TIERS,
7306
7397
  BrowserActionRecorder: () => BrowserActionRecorder,
@@ -7345,9 +7436,12 @@ __export(src_exports, {
7345
7436
  HostedDryRunClient: () => HostedDryRunClient,
7346
7437
  IDLE_WARNING_MINUTES: () => IDLE_WARNING_MINUTES,
7347
7438
  NO_GRADER_REASON: () => NO_GRADER_REASON,
7439
+ PLATFORM_TIMEOUT_DEFAULT_MS: () => PLATFORM_TIMEOUT_DEFAULT_MS,
7440
+ PLATFORM_TIMEOUT_ENV: () => PLATFORM_TIMEOUT_ENV,
7348
7441
  Persona: () => Persona,
7349
7442
  PersonaError: () => PersonaError,
7350
7443
  PersonasClient: () => PersonasClient,
7444
+ PlatformTransport: () => PlatformTransport,
7351
7445
  PushSlugConflict: () => PushSlugConflict,
7352
7446
  RECOVER_BUDGET_MS: () => RECOVER_BUDGET_MS,
7353
7447
  REPLAY_ENVIRONMENT: () => REPLAY_ENVIRONMENT,
@@ -7357,6 +7451,7 @@ __export(src_exports, {
7357
7451
  ReplayReport: () => ReplayReport,
7358
7452
  ReplaySuite: () => ReplaySuite,
7359
7453
  ReplayTask: () => ReplayTask,
7454
+ SANDBOX_REQUEST_TIMEOUT_MS: () => SANDBOX_REQUEST_TIMEOUT_MS,
7360
7455
  SESSION_STATES: () => SESSION_STATES,
7361
7456
  STATUS_WAIT_CAP_SECONDS: () => STATUS_WAIT_CAP_SECONDS,
7362
7457
  STRIP_PREFIX: () => STRIP_PREFIX,
@@ -7375,6 +7470,8 @@ __export(src_exports, {
7375
7470
  TaskSessions: () => TaskSessions,
7376
7471
  ToolStubRegistry: () => ToolStubRegistry,
7377
7472
  TraceDiff: () => TraceDiff,
7473
+ TransportCause: () => TransportCause,
7474
+ UnreachableError: () => UnreachableError,
7378
7475
  UserProfileError: () => UserProfileError,
7379
7476
  UsersClient: () => UsersClient,
7380
7477
  VERIFIER_REWARD_PREFIX: () => VERIFIER_REWARD_PREFIX,
@@ -7469,6 +7566,7 @@ __export(src_exports, {
7469
7566
  parseTransform: () => parseTransform,
7470
7567
  parseWorldTaskRefs: () => parseWorldTaskRefs,
7471
7568
  personas: () => personas,
7569
+ platformTimeoutMs: () => platformTimeoutMs,
7472
7570
  preserveForm: () => preserveForm,
7473
7571
  propose: () => propose,
7474
7572
  pull: () => pull,
@@ -7480,6 +7578,7 @@ __export(src_exports, {
7480
7578
  queryRowsSearch: () => queryRowsSearch,
7481
7579
  readLocalMeta: () => readLocalMeta,
7482
7580
  readToolCallRecords: () => readToolCallRecords,
7581
+ rebaseConflicts: () => rebaseConflicts,
7483
7582
  redactActionArgs: () => redactActionArgs,
7484
7583
  redactionOf: () => redactionOf,
7485
7584
  registerArtifact: () => registerArtifact,
@@ -7519,6 +7618,7 @@ __export(src_exports, {
7519
7618
  tracing: () => tracing,
7520
7619
  uiEntryUrl: () => uiEntryUrl,
7521
7620
  uiUrl: () => uiUrl,
7621
+ uncommittedPaths: () => uncommittedPaths,
7522
7622
  updateTask: () => updateTask,
7523
7623
  upsertRunConfig: () => upsertRunConfig,
7524
7624
  users: () => users,
@@ -15232,9 +15332,12 @@ var tracing = {
15232
15332
  HostedDryRunClient,
15233
15333
  IDLE_WARNING_MINUTES,
15234
15334
  NO_GRADER_REASON,
15335
+ PLATFORM_TIMEOUT_DEFAULT_MS,
15336
+ PLATFORM_TIMEOUT_ENV,
15235
15337
  Persona,
15236
15338
  PersonaError,
15237
15339
  PersonasClient,
15340
+ PlatformTransport,
15238
15341
  PushSlugConflict,
15239
15342
  RECOVER_BUDGET_MS,
15240
15343
  REPLAY_ENVIRONMENT,
@@ -15244,6 +15347,7 @@ var tracing = {
15244
15347
  ReplayReport,
15245
15348
  ReplaySuite,
15246
15349
  ReplayTask,
15350
+ SANDBOX_REQUEST_TIMEOUT_MS,
15247
15351
  SESSION_STATES,
15248
15352
  STATUS_WAIT_CAP_SECONDS,
15249
15353
  STRIP_PREFIX,
@@ -15262,6 +15366,8 @@ var tracing = {
15262
15366
  TaskSessions,
15263
15367
  ToolStubRegistry,
15264
15368
  TraceDiff,
15369
+ TransportCause,
15370
+ UnreachableError,
15265
15371
  UserProfileError,
15266
15372
  UsersClient,
15267
15373
  VERIFIER_REWARD_PREFIX,
@@ -15356,6 +15462,7 @@ var tracing = {
15356
15462
  parseTransform,
15357
15463
  parseWorldTaskRefs,
15358
15464
  personas,
15465
+ platformTimeoutMs,
15359
15466
  preserveForm,
15360
15467
  propose,
15361
15468
  pull,
@@ -15367,6 +15474,7 @@ var tracing = {
15367
15474
  queryRowsSearch,
15368
15475
  readLocalMeta,
15369
15476
  readToolCallRecords,
15477
+ rebaseConflicts,
15370
15478
  redactActionArgs,
15371
15479
  redactionOf,
15372
15480
  registerArtifact,
@@ -15406,6 +15514,7 @@ var tracing = {
15406
15514
  tracing,
15407
15515
  uiEntryUrl,
15408
15516
  uiUrl,
15517
+ uncommittedPaths,
15409
15518
  updateTask,
15410
15519
  upsertRunConfig,
15411
15520
  users,