@withgateway/sdk 0.3.3 → 0.4.0

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 (123) hide show
  1. package/README.md +4 -3
  2. package/dist/cli.js +2221 -962
  3. package/dist/cli.js.map +1 -1
  4. package/dist/cli.mjs +2212 -953
  5. package/dist/cli.mjs.map +1 -1
  6. package/dist/files/index.js +81 -19
  7. package/dist/files/index.js.map +1 -1
  8. package/dist/files/index.mjs +79 -17
  9. package/dist/files/index.mjs.map +1 -1
  10. package/dist/hooks/index.d.mts +1 -1
  11. package/dist/hooks/index.d.ts +1 -1
  12. package/dist/hooks/index.js +124 -11
  13. package/dist/hooks/index.js.map +1 -1
  14. package/dist/hooks/index.mjs +124 -11
  15. package/dist/hooks/index.mjs.map +1 -1
  16. package/dist/{index-C3UzD0G3.d.mts → index-CDPQBsU5.d.mts} +19 -3
  17. package/dist/{index-C3UzD0G3.d.ts → index-CDPQBsU5.d.ts} +19 -3
  18. package/dist/index.d.mts +2 -2
  19. package/dist/index.d.ts +2 -2
  20. package/dist/index.js +903 -221
  21. package/dist/index.js.map +1 -1
  22. package/dist/index.mjs +868 -212
  23. package/dist/index.mjs.map +1 -1
  24. package/dist/traces/index.js +78 -16
  25. package/dist/traces/index.js.map +1 -1
  26. package/dist/traces/index.mjs +76 -14
  27. package/dist/traces/index.mjs.map +1 -1
  28. package/dist/tracing/index.js +7 -1
  29. package/dist/tracing/index.js.map +1 -1
  30. package/dist/tracing/index.mjs +7 -1
  31. package/dist/tracing/index.mjs.map +1 -1
  32. package/dist/worlds/index.d.mts +692 -410
  33. package/dist/worlds/index.d.ts +692 -410
  34. package/dist/worlds/index.js +740 -197
  35. package/dist/worlds/index.js.map +1 -1
  36. package/dist/worlds/index.mjs +736 -193
  37. package/dist/worlds/index.mjs.map +1 -1
  38. package/package.json +1 -1
  39. package/runtime/gatewaysdk/environment/_materialize.py +5 -25
  40. package/runtime/gatewaysdk/environment/_world.py +58 -65
  41. package/runtime/gatewaysdk/environment/backing.py +20 -24
  42. package/runtime/gatewaysdk/environment/core.py +1 -16
  43. package/runtime/gatewaysdk/environment/legacy_sqlite.py +14 -27
  44. package/runtime/gatewaysdk/environment/schema/admission.py +174 -0
  45. package/runtime/gatewaysdk/environment/schema/api.py +174 -471
  46. package/runtime/gatewaysdk/environment/schema/assertions.py +458 -0
  47. package/runtime/gatewaysdk/environment/schema/batch.py +3 -3
  48. package/runtime/gatewaysdk/environment/schema/cache_layout.py +5 -0
  49. package/runtime/gatewaysdk/environment/schema/call_capture.py +309 -0
  50. package/runtime/gatewaysdk/environment/schema/call_log.py +230 -18
  51. package/runtime/gatewaysdk/environment/schema/call_redaction.py +201 -19
  52. package/runtime/gatewaysdk/environment/schema/cast.py +15 -35
  53. package/runtime/gatewaysdk/environment/schema/conform.py +6 -27
  54. package/runtime/gatewaysdk/environment/schema/connector.py +89 -152
  55. package/runtime/gatewaysdk/environment/schema/connectors/confluence/connector.toml +1 -12
  56. package/runtime/gatewaysdk/environment/schema/connectors/github/connector.toml +1 -0
  57. package/runtime/gatewaysdk/environment/schema/connectors/servicenow/connector.toml +2 -5
  58. package/runtime/gatewaysdk/environment/schema/cors.py +54 -0
  59. package/runtime/gatewaysdk/environment/schema/credentials.py +313 -8
  60. package/runtime/gatewaysdk/environment/schema/data.py +14 -13
  61. package/runtime/gatewaysdk/environment/schema/database/base.py +106 -165
  62. package/runtime/gatewaysdk/environment/schema/database/guard.py +43 -36
  63. package/runtime/gatewaysdk/environment/schema/database/reads.py +169 -0
  64. package/runtime/gatewaysdk/environment/schema/database/sqlite.py +57 -31
  65. package/runtime/gatewaysdk/environment/schema/declared_routes.py +210 -0
  66. package/runtime/gatewaysdk/environment/schema/door.py +899 -0
  67. package/runtime/gatewaysdk/environment/schema/envelope.py +86 -28
  68. package/runtime/gatewaysdk/environment/schema/grading.py +58 -86
  69. package/runtime/gatewaysdk/environment/schema/handler_errors.py +25 -4
  70. package/runtime/gatewaysdk/environment/schema/host.py +229 -1695
  71. package/runtime/gatewaysdk/environment/schema/host_control.py +144 -0
  72. package/runtime/gatewaysdk/environment/schema/host_handoff.py +370 -0
  73. package/runtime/gatewaysdk/environment/schema/host_loops.py +97 -0
  74. package/runtime/gatewaysdk/environment/schema/host_owners.py +121 -0
  75. package/runtime/gatewaysdk/environment/schema/host_proxy.py +111 -0
  76. package/runtime/gatewaysdk/environment/schema/host_requests.py +6 -0
  77. package/runtime/gatewaysdk/environment/schema/host_session.py +126 -0
  78. package/runtime/gatewaysdk/environment/schema/host_surfaces.py +79 -21
  79. package/runtime/gatewaysdk/environment/schema/host_transfers.py +127 -0
  80. package/runtime/gatewaysdk/environment/schema/host_versions.py +242 -0
  81. package/runtime/gatewaysdk/environment/schema/host_workers.py +577 -0
  82. package/runtime/gatewaysdk/environment/schema/journal.py +437 -0
  83. package/runtime/gatewaysdk/environment/schema/ledger_spill.py +828 -0
  84. package/runtime/gatewaysdk/environment/schema/local.py +31 -116
  85. package/runtime/gatewaysdk/environment/schema/platform.py +15 -17
  86. package/runtime/gatewaysdk/environment/schema/request_body.py +238 -0
  87. package/runtime/gatewaysdk/environment/schema/request_ledger.py +958 -0
  88. package/runtime/gatewaysdk/environment/schema/route_bindings.py +25 -3
  89. package/runtime/gatewaysdk/environment/schema/route_miss.py +54 -0
  90. package/runtime/gatewaysdk/environment/schema/runtime.py +129 -176
  91. package/runtime/gatewaysdk/environment/schema/session_files.py +133 -24
  92. package/runtime/gatewaysdk/environment/schema/session_move.py +275 -0
  93. package/runtime/gatewaysdk/environment/schema/skills/agents/connector-template-author.md +5 -1
  94. package/runtime/gatewaysdk/environment/schema/skills/benchmarks-getting-started/SKILL.md +8 -9
  95. package/runtime/gatewaysdk/environment/schema/skills/connector-schema-authoring/SKILL.md +31 -6
  96. package/runtime/gatewaysdk/environment/schema/skills/world-data-ingestion/ROWS.md +12 -8
  97. package/runtime/gatewaysdk/environment/schema/skills/world-data-ingestion/SKILL.md +13 -13
  98. package/runtime/gatewaysdk/environment/schema/skills/worlds-getting-started/SKILL.md +23 -23
  99. package/runtime/gatewaysdk/environment/schema/skills/worlds-getting-started/references/cli-mcp-map.md +11 -6
  100. package/runtime/gatewaysdk/environment/schema/skills/worlds-getting-started/references/gotchas.md +35 -2
  101. package/runtime/gatewaysdk/environment/schema/skills/worlds-getting-started/references/journal-checks.md +182 -0
  102. package/runtime/gatewaysdk/environment/schema/snapshot.py +149 -29
  103. package/runtime/gatewaysdk/environment/schema/spill_files.py +228 -0
  104. package/runtime/gatewaysdk/environment/schema/tasks.py +229 -323
  105. package/runtime/gatewaysdk/environment/schema/tools_world.py +84 -203
  106. package/runtime/gatewaysdk/environment/schema/validation.py +69 -1
  107. package/runtime/gatewaysdk/environment/schema/verbs.py +32 -36
  108. package/runtime/gatewaysdk/environment/schema/worker.py +6 -4
  109. package/runtime/gatewaysdk/environment/schema/workers.py +203 -39
  110. package/runtime/gatewaysdk/environment/schema/world_host.py +953 -0
  111. package/runtime/gatewaysdk/environment/schema/world_tests.py +9 -11
  112. package/runtime/gatewaysdk/environment/world.py +1 -1
  113. package/runtime/gatewaysdk/environment/world_session_contract.py +14 -0
  114. package/skills/agents/connector-template-author.md +5 -1
  115. package/skills/benchmarks-getting-started/SKILL.md +8 -9
  116. package/skills/connector-schema-authoring/SKILL.md +31 -6
  117. package/skills/connector-schema-authoring/connector-worlds.md +129 -7
  118. package/skills/world-data-ingestion/ROWS.md +12 -8
  119. package/skills/world-data-ingestion/SKILL.md +13 -13
  120. package/skills/worlds-getting-started/SKILL.md +23 -23
  121. package/skills/worlds-getting-started/references/cli-mcp-map.md +11 -6
  122. package/skills/worlds-getting-started/references/gotchas.md +35 -2
  123. package/skills/worlds-getting-started/references/journal-checks.md +182 -0
@@ -72,7 +72,7 @@ function platformTimeoutMs(env = process.env) {
72
72
  if (Number.isInteger(value) && value > 0) return value;
73
73
  throw new Error(`${PLATFORM_TIMEOUT_ENV} must be a positive whole number of milliseconds, not \`${raw}\`.`);
74
74
  }
75
- var PLATFORM_TIMEOUT_ENV, PLATFORM_TIMEOUT_DEFAULT_MS, CHECK_HOST, RETRY, CAUSES, UNKNOWN_CAUSE, TransportCause, UnreachableError, sleep, RetryPolicy, Attempt, PlatformTransport;
75
+ var PLATFORM_TIMEOUT_ENV, PLATFORM_TIMEOUT_DEFAULT_MS, CHECK_HOST, RETRY, FETCH_LIMIT, CAUSES, UNKNOWN_CAUSE, TransportCause, UnreachableError, sleep, RetryPolicy, Attempt, PlatformTransport;
76
76
  var init_transport = __esm({
77
77
  "src/worlds/transport.ts"() {
78
78
  "use strict";
@@ -80,7 +80,13 @@ var init_transport = __esm({
80
80
  PLATFORM_TIMEOUT_DEFAULT_MS = 12e4;
81
81
  CHECK_HOST = "Check GATEWAY_HOST (or --host) points at a running platform, then retry.";
82
82
  RETRY = "Retry; if it repeats, check the network between here and the platform.";
83
+ FETCH_LIMIT = {
84
+ reason: "Node's fetch stopped waiting after 300 s",
85
+ next: "The platform may still be running it: check what it changed before you retry."
86
+ };
83
87
  CAUSES = {
88
+ UND_ERR_HEADERS_TIMEOUT: FETCH_LIMIT,
89
+ UND_ERR_BODY_TIMEOUT: FETCH_LIMIT,
84
90
  ECONNREFUSED: { reason: "connection refused", next: CHECK_HOST },
85
91
  ENOTFOUND: { reason: "DNS lookup failed", next: CHECK_HOST },
86
92
  EAI_AGAIN: { reason: "DNS lookup failed", next: CHECK_HOST },
@@ -380,6 +386,12 @@ var init_browserReconnect = __esm({
380
386
  });
381
387
 
382
388
  // src/worlds/browser.ts
389
+ function assertSessionAuthMode(value) {
390
+ if (SESSION_AUTH_MODES.includes(value)) return;
391
+ throw new Error(
392
+ `Unknown session auth: ${String(value)}; choose from ${SESSION_AUTH_MODES.join(", ")}`
393
+ );
394
+ }
383
395
  function assertBrowserTier(value) {
384
396
  if (BROWSER_TIERS.includes(value)) return;
385
397
  throw new Error(
@@ -416,6 +428,15 @@ function splitHash(url) {
416
428
  const h = url.indexOf("#");
417
429
  return h < 0 ? [url, ""] : [url.slice(0, h), url.slice(h)];
418
430
  }
431
+ function capabilityLabel(url) {
432
+ let host = "";
433
+ try {
434
+ host = url ? new URL(url).hostname : "";
435
+ } catch {
436
+ return null;
437
+ }
438
+ return CAPABILITY_HOST.exec(host)?.[1] ?? null;
439
+ }
419
440
  function redactActionArgs(action, args) {
420
441
  const secretField = action === "browser_type" && SECRET_KEY.test(String(args.selector ?? ""));
421
442
  const out = {};
@@ -475,7 +496,9 @@ async function openBrowser(surfaces, opts = {}) {
475
496
  };
476
497
  const scrubber = new SecretScrubber([
477
498
  surfaces.browser?.wsUrl,
478
- surfaces.ui?.token
499
+ surfaces.ui?.token,
500
+ capabilityLabel(surfaces.ui?.url),
501
+ capabilityLabel(surfaces.api?.url)
479
502
  ]);
480
503
  const reconnector = mode === "hosted" && surfaces.browser.protocol === "cdp" && opts.repair ? new BrowserReconnector(opts.repair, reattach, {
481
504
  scrub: (text2) => scrubber.scrub(text2)
@@ -540,13 +563,15 @@ function computerUseToolkit(browser, opts = {}) {
540
563
  specs
541
564
  };
542
565
  }
543
- var SURFACE_KINDS, BROWSER_TIERS, DEFAULT_VIEWPORT, SETTLE_TIMEOUT_MS, SETTLE_QUIET_MS, SETTLE_POLL_MS, EVENT_BATCH_SIZE, EVENT_FLUSH_INTERVAL_MS, EVENT_MAX_RETRIES, EVENT_SCREENSHOT_QUALITY, EVENT_MAX_STRING, SECRET_KEY, SECRET_VALUE, WorldSurfaceUnavailable, UI_TOKEN_QUERY, BrowserActionRecorder, WorldBrowser, COMPUTER_USE_SPECS, str;
566
+ var SURFACE_KINDS, PLATFORM_SESSION_HEADER, SESSION_AUTH_MODES, BROWSER_TIERS, DEFAULT_VIEWPORT, SETTLE_TIMEOUT_MS, SETTLE_QUIET_MS, SETTLE_POLL_MS, EVENT_BATCH_SIZE, EVENT_FLUSH_INTERVAL_MS, EVENT_MAX_RETRIES, EVENT_SCREENSHOT_QUALITY, EVENT_MAX_STRING, SECRET_KEY, SECRET_VALUE, WorldSurfaceUnavailable, UI_TOKEN_QUERY, CAPABILITY_HOST, BrowserActionRecorder, WorldBrowser, COMPUTER_USE_SPECS, str;
544
567
  var init_browser = __esm({
545
568
  "src/worlds/browser.ts"() {
546
569
  "use strict";
547
570
  init_session2();
548
571
  init_browserReconnect();
549
572
  SURFACE_KINDS = ["tools", "api", "ui", "browser"];
573
+ PLATFORM_SESSION_HEADER = "X-World-Session";
574
+ SESSION_AUTH_MODES = ["vendor", "open"];
550
575
  BROWSER_TIERS = ["standard", "premium"];
551
576
  DEFAULT_VIEWPORT = { width: 1280, height: 800 };
552
577
  SETTLE_TIMEOUT_MS = 5e3;
@@ -567,6 +592,7 @@ var init_browser = __esm({
567
592
  surface;
568
593
  };
569
594
  UI_TOKEN_QUERY = "token";
595
+ CAPABILITY_HOST = /^o-[a-z0-9]+-([a-z2-7]{26})(?:-api)?\./;
570
596
  BrowserActionRecorder = class {
571
597
  constructor(post, agentId, opts = {}) {
572
598
  this.post = post;
@@ -659,7 +685,10 @@ var init_browser = __esm({
659
685
  }
660
686
  };
661
687
  WorldBrowser = class {
662
- constructor(page, ui, mode, teardown, viewport = DEFAULT_VIEWPORT, recorder = null, reconnector = null, scrubber = new SecretScrubber([ui?.token])) {
688
+ constructor(page, ui, mode, teardown, viewport = DEFAULT_VIEWPORT, recorder = null, reconnector = null, scrubber = new SecretScrubber([
689
+ ui?.token,
690
+ capabilityLabel(ui?.url)
691
+ ])) {
663
692
  this.ui = ui;
664
693
  this.mode = mode;
665
694
  this.teardown = teardown;
@@ -796,7 +825,15 @@ var init_browser = __esm({
796
825
  seq: recorder.nextSeq(),
797
826
  ts: (/* @__PURE__ */ new Date()).toISOString(),
798
827
  action,
799
- args: redactActionArgs(action, args),
828
+ args: redactActionArgs(
829
+ action,
830
+ Object.fromEntries(
831
+ Object.entries(args).map(([key, value]) => [
832
+ key,
833
+ typeof value === "string" ? this.scrubber.scrub(value) : value
834
+ ])
835
+ )
836
+ ),
800
837
  ok: failure === null,
801
838
  error,
802
839
  durationMs: Date.now() - started,
@@ -812,8 +849,8 @@ var init_browser = __esm({
812
849
  screenshot: null
813
850
  };
814
851
  try {
815
- out.url = this.page.url();
816
- out.title = await this.page.title();
852
+ out.url = this.scrubber.scrub(this.page.url());
853
+ out.title = this.scrubber.scrub(await this.page.title());
817
854
  const jpeg = await this.page.screenshot({
818
855
  type: "jpeg",
819
856
  quality: EVENT_SCREENSHOT_QUALITY
@@ -2257,13 +2294,16 @@ function idleWarning(idleExpiresAt, now = /* @__PURE__ */ new Date()) {
2257
2294
  const minutes = Math.max(0, Math.floor(leftMs / 6e4));
2258
2295
  return `warning: session expires in ${minutes}m (idle TTL); call a tool to extend it or \`gateway worlds session pin\` to keep it`;
2259
2296
  }
2260
- var CALL_BODY_LIMIT_BYTES, CALL_BODY_LIMIT_LABEL, IDLE_WARNING_MINUTES, EXPLORATORY_TASK, EXPLORATORY_TASK_SOURCE, NO_GRADER_REASON, WorldCallTooLarge, stillStartingHint;
2297
+ var CALL_BODY_LIMIT_BYTES, CALL_BODY_LIMIT_LABEL, IDLE_WARNING_MINUTES, REQUEST_LOG_PAGE_MAX, REQUEST_BODY_CAPTURE_BYTES, REQUESTS_NOT_RECORDED, EXPLORATORY_TASK, EXPLORATORY_TASK_SOURCE, NO_GRADER_REASON, WorldCallTooLarge, stillStartingHint;
2261
2298
  var init_sessionContract = __esm({
2262
2299
  "src/worlds/sessionContract.ts"() {
2263
2300
  "use strict";
2264
2301
  CALL_BODY_LIMIT_BYTES = 4 * 1024 * 1024;
2265
2302
  CALL_BODY_LIMIT_LABEL = "4mb";
2266
2303
  IDLE_WARNING_MINUTES = 5;
2304
+ REQUEST_LOG_PAGE_MAX = 200;
2305
+ REQUEST_BODY_CAPTURE_BYTES = 64 * 1024;
2306
+ REQUESTS_NOT_RECORDED = "requests_not_recorded";
2267
2307
  EXPLORATORY_TASK = Object.freeze({
2268
2308
  instruction: "exploratory session"
2269
2309
  });
@@ -2297,6 +2337,217 @@ var init_sessionContract = __esm({
2297
2337
  }
2298
2338
  });
2299
2339
 
2340
+ // src/worlds/toolSchema.ts
2341
+ function schemaFromSignature(spec) {
2342
+ if (spec.inputSchema)
2343
+ return {
2344
+ type: "function",
2345
+ function: {
2346
+ name: modelToolName(spec.name),
2347
+ description: spec.doc ?? spec.name,
2348
+ parameters: spec.inputSchema
2349
+ }
2350
+ };
2351
+ const inside = /\(([\s\S]*)\)\s*$/.exec(spec.signature.trim())?.[1] ?? "";
2352
+ const properties = {};
2353
+ const required2 = [];
2354
+ const params = [];
2355
+ let depth = 0;
2356
+ let current = "";
2357
+ for (const ch of inside) {
2358
+ if ("([{".includes(ch)) depth++;
2359
+ if (")]}".includes(ch)) depth--;
2360
+ if (ch === "," && depth === 0) {
2361
+ params.push(current);
2362
+ current = "";
2363
+ } else current += ch;
2364
+ }
2365
+ if (current.trim()) params.push(current);
2366
+ for (const raw of params) {
2367
+ const param = raw.trim();
2368
+ if (!param || param.startsWith("*") || param === "self") continue;
2369
+ const eq = param.indexOf("=");
2370
+ const name = (eq === -1 ? param : param.slice(0, eq)).split(":")[0].trim();
2371
+ if (!name) continue;
2372
+ if (eq === -1) {
2373
+ properties[name] = { type: "string" };
2374
+ required2.push(name);
2375
+ continue;
2376
+ }
2377
+ const value = param.slice(eq + 1).trim();
2378
+ if (/^-?\d+(\.\d+)?$/.test(value)) properties[name] = { type: "number" };
2379
+ else if (value === "True" || value === "False")
2380
+ properties[name] = { type: "boolean" };
2381
+ else properties[name] = { type: "string" };
2382
+ }
2383
+ return {
2384
+ type: "function",
2385
+ function: {
2386
+ name: modelToolName(spec.name),
2387
+ description: spec.doc ?? spec.name,
2388
+ parameters: { type: "object", properties, required: required2 }
2389
+ }
2390
+ };
2391
+ }
2392
+ var modelToolName;
2393
+ var init_toolSchema = __esm({
2394
+ "src/worlds/toolSchema.ts"() {
2395
+ "use strict";
2396
+ modelToolName = (name) => name.replace(/[^A-Za-z0-9_-]/g, "_").slice(0, 64) || "tool";
2397
+ }
2398
+ });
2399
+
2400
+ // src/worlds/requestLedger.ts
2401
+ function platformMessage(text2) {
2402
+ try {
2403
+ const { message } = JSON.parse(text2);
2404
+ return typeof message === "string" ? message : null;
2405
+ } catch {
2406
+ return null;
2407
+ }
2408
+ }
2409
+ var WORLD_REQUEST_VIAS, WorldRequestFilterError, NOT_RECORDED, WorldRequestsNotRecorded, STATUS, INSTANT, WORLDS, SESSIONS, Instant, WorldRequestQuery, WorldRequestLedger;
2410
+ var init_requestLedger = __esm({
2411
+ "src/worlds/requestLedger.ts"() {
2412
+ "use strict";
2413
+ init_worlds();
2414
+ init_sessionContract();
2415
+ WORLD_REQUEST_VIAS = ["api", "ui", "tool"];
2416
+ WorldRequestFilterError = class extends Error {
2417
+ };
2418
+ NOT_RECORDED = "This session's engine records no requests; only hosted World Host sessions do.";
2419
+ WorldRequestsNotRecorded = class _WorldRequestsNotRecorded extends Error {
2420
+ static from(error) {
2421
+ if (!(error instanceof ApiError) || error.code !== REQUESTS_NOT_RECORDED) return error;
2422
+ return new _WorldRequestsNotRecorded(platformMessage(error.text) || NOT_RECORDED);
2423
+ }
2424
+ static async mapped(read) {
2425
+ try {
2426
+ return await read;
2427
+ } catch (error) {
2428
+ throw _WorldRequestsNotRecorded.from(error);
2429
+ }
2430
+ }
2431
+ };
2432
+ STATUS = /^(?:[1-5]\d\d|[1-5]xx)$/;
2433
+ INSTANT = /^(\d{4})-(\d{2})-(\d{2})(?:T(\d{2}):(\d{2})(?::(\d{2})(?:\.(\d{1,3}))?)?(Z|[+-]\d{2}:\d{2})?)?$/;
2434
+ WORLDS = "/api/public/worlds";
2435
+ SESSIONS = "/api/public/world-sessions";
2436
+ Instant = class _Instant {
2437
+ static parse(flag, raw) {
2438
+ const match = INSTANT.exec(raw);
2439
+ const millis = match ? _Instant.fromParts(match) : null;
2440
+ if (millis === null)
2441
+ throw new WorldRequestFilterError(
2442
+ `--${flag} must be an ISO 8601 date or time (2026-10-05, 2026-10-05T14:30:00Z), not \`${raw}\`.`
2443
+ );
2444
+ return millis;
2445
+ }
2446
+ static fromParts(match) {
2447
+ const [year, month, day, hour, minute, second] = [1, 2, 3, 4, 5, 6].map((i) => Number(match[i] ?? 0));
2448
+ const offset = _Instant.offsetMinutes(match[8]);
2449
+ if (offset === null || year < 1 || hour > 23 || minute > 59 || second > 59) return null;
2450
+ const date = /* @__PURE__ */ new Date(0);
2451
+ date.setUTCFullYear(year, month - 1, day);
2452
+ if (date.getUTCFullYear() !== year || date.getUTCMonth() !== month - 1 || date.getUTCDate() !== day) return null;
2453
+ date.setUTCHours(hour, minute, second, Number((match[7] ?? "").padEnd(3, "0")));
2454
+ const utc = date.getTime() - offset * 6e4;
2455
+ const utcYear = new Date(utc).getUTCFullYear();
2456
+ return utcYear < 1 || utcYear > 9999 ? null : utc;
2457
+ }
2458
+ static offsetMinutes(zone) {
2459
+ if (zone === void 0 || zone === "Z") return 0;
2460
+ const hours = Number(zone.slice(1, 3));
2461
+ const minutes = Number(zone.slice(4, 6));
2462
+ if (hours > 23 || minutes > 59) return null;
2463
+ return (zone.startsWith("-") ? -1 : 1) * (hours * 60 + minutes);
2464
+ }
2465
+ };
2466
+ WorldRequestQuery = class _WorldRequestQuery {
2467
+ constructor(entries) {
2468
+ this.entries = entries;
2469
+ }
2470
+ entries;
2471
+ static parse(filter = {}) {
2472
+ const via = _WorldRequestQuery.via(filter.via);
2473
+ const status = _WorldRequestQuery.status(filter.status);
2474
+ const since = filter.since === void 0 ? void 0 : Instant.parse("since", filter.since);
2475
+ const until = filter.until === void 0 ? void 0 : Instant.parse("until", filter.until);
2476
+ if (since !== void 0 && until !== void 0 && since > until)
2477
+ throw new WorldRequestFilterError("--since must not be after --until.");
2478
+ const values = [
2479
+ ["session", filter.session],
2480
+ ["version", filter.version],
2481
+ ["via", via],
2482
+ ["operation", filter.operation],
2483
+ ["status", status],
2484
+ ["since", since === void 0 ? void 0 : new Date(since).toISOString()],
2485
+ ["until", until === void 0 ? void 0 : new Date(until).toISOString()],
2486
+ ["limit", filter.limit === void 0 ? void 0 : String(filter.limit)],
2487
+ ["cursor", filter.cursor]
2488
+ ];
2489
+ return new _WorldRequestQuery(values.filter((entry) => entry[1] !== void 0));
2490
+ }
2491
+ static via(value) {
2492
+ if (value === void 0) return void 0;
2493
+ const lower = value.toLowerCase();
2494
+ if (WORLD_REQUEST_VIAS.includes(lower)) return lower;
2495
+ throw new WorldRequestFilterError(`--via must be one of ${WORLD_REQUEST_VIAS.join(", ")}, not \`${value}\`.`);
2496
+ }
2497
+ static status(value) {
2498
+ if (value === void 0) return void 0;
2499
+ const lower = value.toLowerCase();
2500
+ if (STATUS.test(lower)) return lower;
2501
+ throw new WorldRequestFilterError(`--status must be a code (200) or a class (2xx), not \`${value}\`.`);
2502
+ }
2503
+ get filtered() {
2504
+ return this.entries.some(([key]) => key !== "limit");
2505
+ }
2506
+ params() {
2507
+ return this.entries.map(([key, value]) => [key, value]);
2508
+ }
2509
+ search() {
2510
+ return this.entries.length ? `?${new URLSearchParams(this.entries).toString()}` : "";
2511
+ }
2512
+ };
2513
+ WorldRequestLedger = class {
2514
+ constructor(options = {}) {
2515
+ this.options = options;
2516
+ }
2517
+ options;
2518
+ /** A page of the world's requests, newest first; `nextCursor` reads the page after it. Narrowed to a session
2519
+ * whose engine records none: `WorldRequestsNotRecorded`. */
2520
+ list(slug, query = WorldRequestQuery.parse()) {
2521
+ return WorldRequestsNotRecorded.mapped(
2522
+ apiRequest(
2523
+ this.options,
2524
+ "GET",
2525
+ `${WORLDS}/${encodeURIComponent(slug)}/requests${query.search()}`
2526
+ )
2527
+ );
2528
+ }
2529
+ /** One of the world's requests, with its headers and bodies. */
2530
+ get(slug, requestId) {
2531
+ return apiRequest(
2532
+ this.options,
2533
+ "GET",
2534
+ `${WORLDS}/${encodeURIComponent(slug)}/requests/${encodeURIComponent(requestId)}`
2535
+ );
2536
+ }
2537
+ /** A page of one session's requests, newest first; `WorldRequestsNotRecorded` when its engine records none. */
2538
+ forSession(sessionId, query = WorldRequestQuery.parse()) {
2539
+ return WorldRequestsNotRecorded.mapped(
2540
+ apiRequest(
2541
+ this.options,
2542
+ "GET",
2543
+ `${SESSIONS}/${encodeURIComponent(sessionId)}/requests${query.search()}`
2544
+ )
2545
+ );
2546
+ }
2547
+ };
2548
+ }
2549
+ });
2550
+
2300
2551
  // src/worlds/sessionReadiness.ts
2301
2552
  var READY_TIMEOUT_MS, READY_POLL_MS, sleep2, WorldSessionTimeout, WorldSessionCallError, WorldSessionOpenFailed, ENDED, SessionReadiness;
2302
2553
  var init_sessionReadiness = __esm({
@@ -2635,57 +2886,6 @@ __export(session_exports2, {
2635
2886
  schemaFromSignature: () => schemaFromSignature,
2636
2887
  taskLabel: () => taskLabel
2637
2888
  });
2638
- function schemaFromSignature(spec) {
2639
- if (spec.inputSchema)
2640
- return {
2641
- type: "function",
2642
- function: {
2643
- name: modelToolName(spec.name),
2644
- description: spec.doc ?? spec.name,
2645
- parameters: spec.inputSchema
2646
- }
2647
- };
2648
- const inside = /\(([\s\S]*)\)\s*$/.exec(spec.signature.trim())?.[1] ?? "";
2649
- const properties = {};
2650
- const required2 = [];
2651
- const params = [];
2652
- let depth = 0;
2653
- let current = "";
2654
- for (const ch of inside) {
2655
- if ("([{".includes(ch)) depth++;
2656
- if (")]}".includes(ch)) depth--;
2657
- if (ch === "," && depth === 0) {
2658
- params.push(current);
2659
- current = "";
2660
- } else current += ch;
2661
- }
2662
- if (current.trim()) params.push(current);
2663
- for (const raw of params) {
2664
- const param = raw.trim();
2665
- if (!param || param.startsWith("*") || param === "self") continue;
2666
- const eq = param.indexOf("=");
2667
- const name = (eq === -1 ? param : param.slice(0, eq)).split(":")[0].trim();
2668
- if (!name) continue;
2669
- if (eq === -1) {
2670
- properties[name] = { type: "string" };
2671
- required2.push(name);
2672
- continue;
2673
- }
2674
- const value = param.slice(eq + 1).trim();
2675
- if (/^-?\d+(\.\d+)?$/.test(value)) properties[name] = { type: "number" };
2676
- else if (value === "True" || value === "False")
2677
- properties[name] = { type: "boolean" };
2678
- else properties[name] = { type: "string" };
2679
- }
2680
- return {
2681
- type: "function",
2682
- function: {
2683
- name: modelToolName(spec.name),
2684
- description: spec.doc ?? spec.name,
2685
- parameters: { type: "object", properties, required: required2 }
2686
- }
2687
- };
2688
- }
2689
2889
  async function attachSession(sessionId, options = {}) {
2690
2890
  const state2 = await apiRequest(
2691
2891
  options,
@@ -2706,6 +2906,7 @@ async function openSession(slugOrRef, taskOrOpts = {}, positionalOpts = {}) {
2706
2906
  `Unknown world surfaces: ${unknown.join(", ")}; choose from ${SURFACE_KINDS.join(", ")}`
2707
2907
  );
2708
2908
  if (opts.browserTier !== void 0) assertBrowserTier(opts.browserTier);
2909
+ if (opts.auth !== void 0) assertSessionAuthMode(opts.auth);
2709
2910
  const at = slugOrRef.indexOf("@");
2710
2911
  const slug = at === -1 ? slugOrRef : slugOrRef.slice(0, at);
2711
2912
  const ref = at === -1 ? "" : slugOrRef.slice(at + 1);
@@ -2718,7 +2919,8 @@ async function openSession(slugOrRef, taskOrOpts = {}, positionalOpts = {}) {
2718
2919
  ...task === void 0 ? {} : { task },
2719
2920
  ...opts.reuseWarm === void 0 ? {} : { reuseWarm: opts.reuseWarm },
2720
2921
  ...opts.surfaces?.length ? { surfaces: opts.surfaces } : {},
2721
- ...opts.browserTier === void 0 ? {} : { browserTier: opts.browserTier }
2922
+ ...opts.browserTier === void 0 ? {} : { browserTier: opts.browserTier },
2923
+ ...opts.auth === void 0 ? {} : { auth: opts.auth }
2722
2924
  }
2723
2925
  );
2724
2926
  return new WorldSession(state2.sessionId, state2, options);
@@ -2799,7 +3001,7 @@ async function runSessions(opts) {
2799
3001
  passed: failed === 0 && (opts.failUnder === void 0 || mean >= opts.failUnder)
2800
3002
  };
2801
3003
  }
2802
- var import_node_crypto2, CALL_TIMEOUT_MS, CALL_POLL_MS, JUDGED_GRADE_TIMEOUT_MS, JUDGED_GRADE_POLL_MS, EXPORT_PAGE, sleep3, modelToolName, WorldSession, OPEN_SESSION_OPTION_KEYS, isOpenSessionOptions;
3004
+ var import_node_crypto2, CALL_TIMEOUT_MS, CALL_POLL_MS, JUDGED_GRADE_TIMEOUT_MS, JUDGED_GRADE_POLL_MS, EXPORT_PAGE, sleep3, WorldSession, OPEN_SESSION_OPTION_KEYS, isOpenSessionOptions;
2803
3005
  var init_session2 = __esm({
2804
3006
  "src/worlds/session.ts"() {
2805
3007
  "use strict";
@@ -2808,6 +3010,8 @@ var init_session2 = __esm({
2808
3010
  init_browser();
2809
3011
  init_nativeComputer();
2810
3012
  init_sessionContract();
3013
+ init_toolSchema();
3014
+ init_requestLedger();
2811
3015
  init_sessionReadiness();
2812
3016
  init_session();
2813
3017
  init_taskRef();
@@ -2821,7 +3025,6 @@ var init_session2 = __esm({
2821
3025
  JUDGED_GRADE_POLL_MS = 2e3;
2822
3026
  EXPORT_PAGE = 500;
2823
3027
  sleep3 = (ms) => new Promise((r) => setTimeout(r, ms));
2824
- modelToolName = (name) => name.replace(/[^A-Za-z0-9_-]/g, "_").slice(0, 64) || "tool";
2825
3028
  WorldSession = class {
2826
3029
  constructor(sessionId, current, options) {
2827
3030
  this.sessionId = sessionId;
@@ -2891,12 +3094,12 @@ var init_session2 = __esm({
2891
3094
  );
2892
3095
  return api2.url;
2893
3096
  }
2894
- /** Headers every request to `api()` needs. A World Host session gates its
2895
- * api surface on a per-session token; a pod or hosted twin answers with the
2896
- * world's own declared auth and this is `{}`. */
3097
+ /** Headers every request to `api()` needs: a World Host session's token in the
3098
+ * platform's `X-World-Session` header, which every world takes; `{}` for a pod
3099
+ * or hosted twin, which answers with the world's own declared auth. */
2897
3100
  async apiHeaders() {
2898
3101
  const { api: api2 } = await this.surfaces();
2899
- return api2?.token ? { Authorization: `Bearer ${api2.token}` } : {};
3102
+ return api2?.token ? { [PLATFORM_SESSION_HEADER]: api2.token } : {};
2900
3103
  }
2901
3104
  /** URL of the world's UI entry page for this session. */
2902
3105
  async ui() {
@@ -2967,11 +3170,28 @@ var init_session2 = __esm({
2967
3170
  }
2968
3171
  /** The session's latest platform state (one request, no waiting). */
2969
3172
  async status() {
3173
+ return this.refresh(
3174
+ await apiRequest(
3175
+ this.options,
3176
+ "GET",
3177
+ `/api/public/world-sessions/${encodeURIComponent(this.sessionId)}`
3178
+ )
3179
+ );
3180
+ }
3181
+ /** The world started over under the same id, URLs and token, on what its pin (or `version`, which becomes
3182
+ * its pin) resolves to now: base data plus the task's seed. A grade then reads only the new world's requests. */
3183
+ async restart(opts = {}) {
2970
3184
  const fresh = await apiRequest(
2971
3185
  this.options,
2972
- "GET",
2973
- `/api/public/world-sessions/${encodeURIComponent(this.sessionId)}`
3186
+ "POST",
3187
+ `/api/public/world-sessions/${encodeURIComponent(this.sessionId)}/restart`,
3188
+ opts.version ? { version: opts.version } : {}
2974
3189
  );
3190
+ this.refresh(fresh);
3191
+ return fresh;
3192
+ }
3193
+ // A status read carries neither the objective nor the open's notices; keep the ones we opened with.
3194
+ refresh(fresh) {
2975
3195
  this.current = {
2976
3196
  instruction: this.current.instruction,
2977
3197
  tools: this.current.tools,
@@ -3006,7 +3226,7 @@ var init_session2 = __esm({
3006
3226
  const { callId } = enqueued;
3007
3227
  const judged = enqueued.pending === true;
3008
3228
  const budgetMs = timeoutMs ?? (judged ? JUDGED_GRADE_TIMEOUT_MS : CALL_TIMEOUT_MS);
3009
- const pollMs2 = judged ? JUDGED_GRADE_POLL_MS : CALL_POLL_MS;
3229
+ const pollMs = judged ? JUDGED_GRADE_POLL_MS : CALL_POLL_MS;
3010
3230
  const deadline = Date.now() + budgetMs;
3011
3231
  for (; ; ) {
3012
3232
  const call = await apiRequest(
@@ -3022,7 +3242,7 @@ var init_session2 = __esm({
3022
3242
  throw new WorldSessionTimeout(
3023
3243
  judged ? `Grade ${callId} still ${call.state} after ${Math.round(budgetMs / 1e3)}s \u2014 the judge has not answered; the platform finalizes the call on its own, read it back with export().` : `Call ${callId} still ${call.state} after ${Math.round(budgetMs / 1e3)}s \u2014 the container may have died.`
3024
3244
  );
3025
- await sleep3(pollMs2);
3245
+ await sleep3(pollMs);
3026
3246
  }
3027
3247
  }
3028
3248
  /**
@@ -3115,19 +3335,31 @@ var init_session2 = __esm({
3115
3335
  async reset(opts = {}) {
3116
3336
  await this.exchange({ kind: "reset" }, opts.timeoutMs);
3117
3337
  }
3338
+ /** One page of the session's entries in its world's request ledger, newest
3339
+ * first and without bodies: at most `limit` after `cursor` (the last page's
3340
+ * `nextCursor`). Reading it records nothing in the session. */
3341
+ async requests(opts = {}) {
3342
+ return new WorldRequestLedger(this.options).forSession(
3343
+ this.sessionId,
3344
+ WorldRequestQuery.parse({ cursor: opts.cursor, limit: opts.limit ?? REQUEST_LOG_PAGE_MAX })
3345
+ );
3346
+ }
3347
+ page(route, limit, cursor) {
3348
+ const query = new URLSearchParams({ limit: String(limit) });
3349
+ if (cursor) query.set("cursor", cursor);
3350
+ return apiRequest(
3351
+ this.options,
3352
+ "GET",
3353
+ `/api/public/world-sessions/${encodeURIComponent(this.sessionId)}/${route}?${query.toString()}`
3354
+ );
3355
+ }
3118
3356
  /** The session's call log, oldest first: every tool call, seed, reset,
3119
3357
  * grade with its result — the record of the episode. */
3120
3358
  async export() {
3121
3359
  const calls = [];
3122
3360
  let cursor;
3123
3361
  do {
3124
- const params = new URLSearchParams({ limit: String(EXPORT_PAGE) });
3125
- if (cursor) params.set("cursor", cursor);
3126
- const page = await apiRequest(
3127
- this.options,
3128
- "GET",
3129
- `/api/public/world-sessions/${encodeURIComponent(this.sessionId)}/calls?${params.toString()}`
3130
- );
3362
+ const page = await this.page("calls", EXPORT_PAGE, cursor);
3131
3363
  for (const call of page.calls) {
3132
3364
  calls.push({
3133
3365
  seq: Number(call.seq),
@@ -3209,6 +3441,7 @@ var init_session2 = __esm({
3209
3441
  "reuseWarm",
3210
3442
  "surfaces",
3211
3443
  "browserTier",
3444
+ "auth",
3212
3445
  "options"
3213
3446
  ]);
3214
3447
  isOpenSessionOptions = (value) => typeof value === "object" && value !== null && Object.keys(value).every((key) => OPEN_SESSION_OPTION_KEYS.has(key));
@@ -3323,11 +3556,50 @@ var init_tasks = __esm({
3323
3556
  }
3324
3557
  });
3325
3558
 
3559
+ // src/worlds/taskGrades.ts
3560
+ var TASKS2, compact2, TaskGrades;
3561
+ var init_taskGrades = __esm({
3562
+ "src/worlds/taskGrades.ts"() {
3563
+ "use strict";
3564
+ init_worlds();
3565
+ TASKS2 = "/api/public/world-tasks";
3566
+ compact2 = (body) => Object.fromEntries(Object.entries(body).filter(([, v]) => v !== void 0));
3567
+ TaskGrades = class {
3568
+ constructor(options = {}) {
3569
+ this.options = options;
3570
+ }
3571
+ options;
3572
+ try(sessionId, target) {
3573
+ return apiRequest(
3574
+ this.options,
3575
+ "POST",
3576
+ `${TASKS2}/try`,
3577
+ compact2({ sessionId, ...target })
3578
+ );
3579
+ }
3580
+ regrade(taskId, scope = {}) {
3581
+ return apiRequest(
3582
+ this.options,
3583
+ "POST",
3584
+ `${TASKS2}/${encodeURIComponent(taskId)}/regrade`,
3585
+ compact2({ ...scope })
3586
+ );
3587
+ }
3588
+ };
3589
+ }
3590
+ });
3591
+
3326
3592
  // src/worlds/surfaceDescriptor.ts
3327
3593
  function surfaceDescriptor(s) {
3328
3594
  return {
3329
3595
  surfaces: surfaceKinds(s),
3330
- ...s.api ? { api: { url: s.api.url, ...s.api.token ? { token: s.api.token } : {} } } : {},
3596
+ ...s.api ? {
3597
+ api: {
3598
+ url: s.api.url,
3599
+ ...s.api.token ? { token: s.api.token } : {},
3600
+ ...s.api.auth ? { auth: s.api.auth } : {}
3601
+ }
3602
+ } : {},
3331
3603
  ...s.ui ? { ui: { url: s.ui.url, entry: uiEntryUrl(s.ui), apiPath: s.ui.apiPath ?? null } } : {},
3332
3604
  ...s.browser ? {
3333
3605
  browser: {
@@ -3377,8 +3649,7 @@ function fromResponse(answer, options) {
3377
3649
  sessions[alias] = new WorldSession(state2.sessionId, state2, options);
3378
3650
  worlds[alias] = {
3379
3651
  slug: state2.slug,
3380
- ref: state2.ref,
3381
- private: state2.private ?? null
3652
+ ref: state2.ref
3382
3653
  };
3383
3654
  }
3384
3655
  return new TaskSessions(
@@ -3453,7 +3724,6 @@ async function attachTask(taskId, options = {}) {
3453
3724
  {
3454
3725
  slug: row.slug ?? "",
3455
3726
  ref: null,
3456
- private: null,
3457
3727
  versionId: row.versionId,
3458
3728
  sessionId: row.sessionId,
3459
3729
  ready: row.ready,
@@ -3483,7 +3753,7 @@ async function attachManifest(manifest, options = {}) {
3483
3753
  Object.fromEntries(
3484
3754
  Object.entries(manifest.sessions).map(([alias, entry]) => [
3485
3755
  alias,
3486
- { slug: entry.slug, ref: entry.ref, private: entry.private ?? null }
3756
+ { slug: entry.slug, ref: entry.ref }
3487
3757
  ])
3488
3758
  )
3489
3759
  );
@@ -3505,7 +3775,6 @@ var init_taskSessions = __esm({
3505
3775
  manifestSession = (s, state2, world) => ({
3506
3776
  slug: world.slug,
3507
3777
  ref: world.ref,
3508
- private: world.private,
3509
3778
  versionId: state2.versionId,
3510
3779
  sessionId: state2.sessionId,
3511
3780
  ready: state2.ready,
@@ -3562,7 +3831,7 @@ var init_taskSessions = __esm({
3562
3831
  /** This alias's world as recorded at open/attach — what a `TaskRun`
3563
3832
  * filing needs to name, without exposing the whole map. */
3564
3833
  worldRef(alias) {
3565
- return this.worlds[alias] ?? { slug: "", ref: null, private: null };
3834
+ return this.worlds[alias] ?? { slug: "", ref: null };
3566
3835
  }
3567
3836
  /** The aliases, in the spec's order. */
3568
3837
  get aliases() {
@@ -3887,16 +4156,12 @@ var init_taskRunOutcome = __esm({
3887
4156
  evaluationId;
3888
4157
  evaluationStatus = null;
3889
4158
  started = Date.now();
3890
- /** The run stopped short of a grade; the first reason stands. */
3891
4159
  stopped(error) {
3892
4160
  this.runError ??= messageOf(error).slice(0, 2e3);
3893
4161
  }
3894
4162
  agentRaised(error) {
3895
4163
  this.agentError = messageOf(error).slice(0, 2e3);
3896
4164
  }
3897
- /** Every reason the run failed, on one line: the evaluation's
3898
- * `metrics.error`. A run that never reached a grade has failed whatever
3899
- * its reasons say. */
3900
4165
  failure() {
3901
4166
  const reasons = [
3902
4167
  this.agentError === null ? null : `agent raised: ${this.agentError}`,
@@ -3992,6 +4257,7 @@ var init_taskRunOutcome = __esm({
3992
4257
  ])
3993
4258
  ),
3994
4259
  ungraded: this.grade?.ungraded ?? live.aliases,
4260
+ verifierVersion: live.taskVersion,
3995
4261
  traced: this.traced,
3996
4262
  runDir: this.runDir,
3997
4263
  ...this.agentError ? { agentError: this.agentError } : {},
@@ -4752,7 +5018,7 @@ var require_package = __commonJS({
4752
5018
  "package.json"(exports2, module2) {
4753
5019
  module2.exports = {
4754
5020
  name: "@withgateway/sdk",
4755
- version: "0.3.3",
5021
+ version: "0.4.0",
4756
5022
  description: "Gateway SDK for TypeScript - A/B experiments, tracing, and observability",
4757
5023
  main: "./dist/index.js",
4758
5024
  module: "./dist/index.mjs",
@@ -5944,45 +6210,83 @@ var init_setRun = __esm({
5944
6210
  });
5945
6211
 
5946
6212
  // src/worlds/requestLog.ts
5947
- var WorldRequestLog;
6213
+ function worldRequestsUnrecorded(counts) {
6214
+ const parts = UNRECORDED.map(([field2, one, many]) => [counted(counts[field2]), one, many]).filter(([count]) => count > 0).map(([count, one, many]) => (count === 1 ? one : many).replace("{n}", String(count)));
6215
+ return parts.length > 0 ? `Not recorded: ${parts.join(", ")}` : null;
6216
+ }
6217
+ function counted(value) {
6218
+ return typeof value === "number" && Number.isSafeInteger(value) && value > 0 ? value : 0;
6219
+ }
6220
+ var UNRECORDED, WorldRequestLog;
5948
6221
  var init_requestLog = __esm({
5949
6222
  "src/worlds/requestLog.ts"() {
5950
6223
  "use strict";
6224
+ init_requestLedger();
6225
+ UNRECORDED = [
6226
+ ["lost", "{n} request", "{n} requests"],
6227
+ ["shed", "{n} request's headers and bodies", "{n} requests' headers and bodies"],
6228
+ ["hostsLost", "the requests {n} lost host held", "the requests {n} lost hosts held"]
6229
+ ];
5951
6230
  WorldRequestLog = class _WorldRequestLog {
5952
- constructor(requests) {
6231
+ constructor(requests, notRecorded = null, unrecorded = null) {
5953
6232
  this.requests = requests;
6233
+ this.notRecorded = notRecorded;
6234
+ this.unrecorded = unrecorded;
5954
6235
  }
5955
6236
  requests;
5956
- static async read(session) {
5957
- const state2 = await session.state();
5958
- const calls = state2?.calls;
5959
- if (!Array.isArray(calls)) return null;
5960
- return new _WorldRequestLog(calls.filter((c) => typeof c === "object" && c !== null));
5961
- }
5962
- /** How many older requests the world no longer keeps (its log is bounded): the gap
5963
- * before the first entry it still holds. */
5964
- get dropped() {
5965
- const first = Number(this.requests[0]?.seq) || 1;
5966
- return Math.max(0, first - 1);
5967
- }
5968
- /** Each request in the shape of a ledger line, `kind: "request"`, so one JSONL
5969
- * file holds both. */
6237
+ notRecorded;
6238
+ unrecorded;
6239
+ /** Every entry the ledger holds for the session, oldest first, and the line for what it did not record;
6240
+ * for a session the World Host did not serve, none, and `notRecorded` says why. */
6241
+ static async load(session) {
6242
+ try {
6243
+ return await _WorldRequestLog.pages(session);
6244
+ } catch (error) {
6245
+ const refused = WorldRequestsNotRecorded.from(error);
6246
+ if (!(refused instanceof WorldRequestsNotRecorded)) throw error;
6247
+ return new _WorldRequestLog([], refused.message);
6248
+ }
6249
+ }
6250
+ static async pages(session) {
6251
+ const requests = [];
6252
+ let cursor;
6253
+ for (; ; ) {
6254
+ const page = await session.requests(cursor ? { cursor } : {});
6255
+ requests.push(...page.requests);
6256
+ if (!page.nextCursor || page.requests.length === 0)
6257
+ return new _WorldRequestLog(requests.reverse(), null, worldRequestsUnrecorded(page));
6258
+ cursor = page.nextCursor;
6259
+ }
6260
+ }
6261
+ /** Each entry in the shape of a ledger line, `kind: "request"`, so one JSONL
6262
+ * file holds both: `args` what was asked, `result` what came back under the
6263
+ * entry's `requestId`. */
5970
6264
  asCalls() {
5971
6265
  return this.requests.map((r) => ({
5972
- seq: Number(r.seq) || 0,
6266
+ seq: r.seq,
5973
6267
  kind: "request",
5974
- tool: r.operation ?? null,
6268
+ tool: r.operation,
5975
6269
  args: {
5976
- method: r.method ?? null,
5977
- path: r.path ?? null,
5978
- args: r.args ?? null,
5979
- query: r.query ?? null,
5980
- body: r.body ?? null,
5981
- via: r.via ?? null
6270
+ method: r.method,
6271
+ path: r.path,
6272
+ query: r.query,
6273
+ via: r.via,
6274
+ contentType: r.request.contentType,
6275
+ bodyBytes: r.request.bodyBytes,
6276
+ truncated: r.request.truncated
6277
+ },
6278
+ result: {
6279
+ requestId: r.id,
6280
+ status: r.response.status,
6281
+ rows: r.rows,
6282
+ found: r.found,
6283
+ durationMs: r.durationMs,
6284
+ contentType: r.response.contentType,
6285
+ bodyBytes: r.response.bodyBytes,
6286
+ truncated: r.response.truncated
5982
6287
  },
5983
- result: { status: r.status ?? null, rows: r.rows ?? null, found: r.found ?? null },
5984
6288
  error: null,
5985
- completedAt: r.at ?? null
6289
+ completedAt: r.at
5986
6290
  }));
5987
6291
  }
5988
6292
  };
@@ -6673,7 +6977,8 @@ function checkoutIdentity(ref, resolved) {
6673
6977
  async function pull(slugRef, target, options = {}, opts = {}) {
6674
6978
  const at = slugRef.indexOf("@");
6675
6979
  const slug = at === -1 ? slugRef : slugRef.slice(0, at);
6676
- const ref = at === -1 ? "latest" : slugRef.slice(at + 1);
6980
+ const asked = at === -1 ? void 0 : slugRef.slice(at + 1);
6981
+ const ref = asked ?? "latest";
6677
6982
  const landing = CheckoutTarget.resolve(slug, target, {
6678
6983
  cwd: process.cwd(),
6679
6984
  force: opts.force ?? false,
@@ -6681,7 +6986,7 @@ async function pull(slugRef, target, options = {}, opts = {}) {
6681
6986
  });
6682
6987
  const details = await apiRequest(options, "POST", "/api/public/benchmark-containers/resolve-version", {
6683
6988
  slug,
6684
- ref
6989
+ ...asked ? { ref: asked } : {}
6685
6990
  });
6686
6991
  if (!details.downloadUrl) {
6687
6992
  throw new Error(`${slug}@${ref} resolved but has no uploaded bundle`);
@@ -6871,7 +7176,7 @@ async function validateWorld(dir, opts) {
6871
7176
  options,
6872
7177
  "POST",
6873
7178
  "/api/public/benchmark-containers/resolve-version",
6874
- { slug, ref: branch }
7179
+ { slug, ...branch === DEFAULT_BRANCH ? {} : { ref: branch } }
6875
7180
  );
6876
7181
  tipVersionId = tip.versionId ?? null;
6877
7182
  } catch {
@@ -6983,6 +7288,10 @@ function parseSlugRef(slugRef) {
6983
7288
  if (at === -1) return { slug: slugRef };
6984
7289
  return { slug: slugRef.slice(0, at), ref: slugRef.slice(at + 1) };
6985
7290
  }
7291
+ function nameGlob(pattern) {
7292
+ const literal = (part) => part.replace(/[.+?^${}()|[\]\\]/g, "\\$&");
7293
+ return new RegExp(`^${pattern.split("*").map(literal).join(".*")}$`);
7294
+ }
6986
7295
  function rebaseConflicts(error) {
6987
7296
  if (!(error instanceof ApiError) || error.status !== 409) return null;
6988
7297
  let body;
@@ -7000,7 +7309,8 @@ function isConflictPath(value) {
7000
7309
  return typeof entry?.path === "string" && typeof entry.reason === "string";
7001
7310
  }
7002
7311
  function uncommittedPaths(error) {
7003
- if (!(error instanceof ApiError) || error.status !== 409 || error.code !== "sandbox_uncommitted") return null;
7312
+ if (!(error instanceof ApiError) || error.status !== 409 || error.code !== "sandbox_uncommitted")
7313
+ return null;
7004
7314
  let body;
7005
7315
  try {
7006
7316
  body = JSON.parse(error.text);
@@ -7011,6 +7321,53 @@ function uncommittedPaths(error) {
7011
7321
  if (!Array.isArray(uncommitted)) return null;
7012
7322
  return uncommitted.filter((p) => typeof p === "string");
7013
7323
  }
7324
+ function carriedWarnings(error) {
7325
+ const kept = typeof error === "object" && error !== null ? carried.get(error) ?? [] : [];
7326
+ const shown = error instanceof Error ? error.message : "";
7327
+ return unique([...kept, ...bodyWarnings(error)]).filter((warning) => !shown.includes(warning));
7328
+ }
7329
+ function carrying(error, warnings) {
7330
+ if (warnings.length > 0 && typeof error === "object" && error !== null)
7331
+ carried.set(error, unique([...carried.get(error) ?? [], ...warnings]));
7332
+ return error;
7333
+ }
7334
+ function unique(warnings) {
7335
+ return [...new Set(warnings)];
7336
+ }
7337
+ function bodyWarnings(error) {
7338
+ if (!(error instanceof ApiError)) return [];
7339
+ let body;
7340
+ try {
7341
+ body = JSON.parse(error.text);
7342
+ } catch {
7343
+ return [];
7344
+ }
7345
+ const warnings = body?.warnings;
7346
+ if (!Array.isArray(warnings)) return [];
7347
+ return warnings.filter((w) => typeof w === "string");
7348
+ }
7349
+ function deferredWarnings(error) {
7350
+ if (!(error instanceof ApiError) || error.status !== 409 || error.code !== "sandbox_exec_deferred") return null;
7351
+ return bodyWarnings(error);
7352
+ }
7353
+ function rowsRefusal(error) {
7354
+ if (!(error instanceof ApiError) || error.status !== 400 || error.code !== "rows_refused") return null;
7355
+ let body;
7356
+ try {
7357
+ body = JSON.parse(error.text);
7358
+ } catch {
7359
+ return null;
7360
+ }
7361
+ const { message, batchId, refusalCount, refusals, reportUrl } = body;
7362
+ if (typeof batchId !== "string" || typeof refusalCount !== "number" || !Array.isArray(refusals)) return null;
7363
+ return {
7364
+ message: typeof message === "string" ? message : "",
7365
+ batchId,
7366
+ refusalCount,
7367
+ refusals: refusals.filter((r) => typeof r === "object" && r !== null),
7368
+ reportUrl: typeof reportUrl === "string" ? reportUrl : null
7369
+ };
7370
+ }
7014
7371
  function listQuery(filter) {
7015
7372
  const params = new URLSearchParams();
7016
7373
  if (filter.status) params.set("status", filter.status);
@@ -7019,15 +7376,52 @@ function listQuery(filter) {
7019
7376
  const qs = params.toString();
7020
7377
  return qs ? `?${qs}` : "";
7021
7378
  }
7022
- var isSandboxImportPending, sid, SANDBOXES, SANDBOX_REQUEST_TIMEOUT_MS, WorldSandboxClient;
7379
+ var import_node_crypto7, isSandboxCommitPending, isSandboxImportPending, sid, SANDBOXES, SANDBOX_REQUEST_TIMEOUT_MS, SANDBOX_WRITE_CHUNK_BYTES, SANDBOX_FILE_MAX_BYTES, SANDBOX_WRITE_SKIPPED, WriteTreeFilter, SANDBOX_EXEC_WAIT_MS, SANDBOX_EXEC_TIMEOUT_MAX_S, SANDBOX_EXEC_REPORT_MARGIN_MS, SANDBOX_EXEC_START_ATTEMPTS, carried, WorldSandboxClient;
7023
7380
  var init_sandbox = __esm({
7024
7381
  "src/worlds/sandbox.ts"() {
7025
7382
  "use strict";
7383
+ import_node_crypto7 = require("crypto");
7026
7384
  init_worlds();
7385
+ isSandboxCommitPending = (answer) => !("versionId" in answer);
7027
7386
  isSandboxImportPending = (answer) => !("versionId" in answer);
7028
7387
  sid = encodeURIComponent;
7029
7388
  SANDBOXES = "/api/public/benchmark-containers/sandboxes";
7030
- SANDBOX_REQUEST_TIMEOUT_MS = 66e4;
7389
+ SANDBOX_REQUEST_TIMEOUT_MS = 29e4;
7390
+ SANDBOX_WRITE_CHUNK_BYTES = 4 * 1024 * 1024;
7391
+ SANDBOX_FILE_MAX_BYTES = 256 * 1024 * 1024;
7392
+ SANDBOX_WRITE_SKIPPED = [
7393
+ ".git/",
7394
+ ".gateway/",
7395
+ "scratch/",
7396
+ ".scratch/",
7397
+ "__pycache__/",
7398
+ "*.pyc",
7399
+ ".pytest_cache/",
7400
+ ".mypy_cache/",
7401
+ ".ruff_cache/",
7402
+ "node_modules/",
7403
+ ".venv/",
7404
+ "venv/",
7405
+ ".DS_Store",
7406
+ "*.swp"
7407
+ ];
7408
+ WriteTreeFilter = class {
7409
+ directories = new Set(
7410
+ SANDBOX_WRITE_SKIPPED.filter((pattern) => pattern.endsWith("/")).map((pattern) => pattern.slice(0, -1))
7411
+ );
7412
+ files = SANDBOX_WRITE_SKIPPED.filter((pattern) => !pattern.endsWith("/")).map(nameGlob);
7413
+ skipsDirectory(name) {
7414
+ return this.directories.has(name);
7415
+ }
7416
+ skipsFile(name) {
7417
+ return this.files.some((glob) => glob.test(name));
7418
+ }
7419
+ };
7420
+ SANDBOX_EXEC_WAIT_MS = 4e4;
7421
+ SANDBOX_EXEC_TIMEOUT_MAX_S = 600;
7422
+ SANDBOX_EXEC_REPORT_MARGIN_MS = 35e3;
7423
+ SANDBOX_EXEC_START_ATTEMPTS = 3;
7424
+ carried = /* @__PURE__ */ new WeakMap();
7031
7425
  WorldSandboxClient = class {
7032
7426
  constructor(options = {}) {
7033
7427
  this.options = options;
@@ -7052,7 +7446,10 @@ var init_sandbox = __esm({
7052
7446
  }
7053
7447
  /** The project's sandboxes, newest first — how an agent finds one it left open. */
7054
7448
  async list(filter = {}) {
7055
- const res = await this.request("GET", `${SANDBOXES}${listQuery(filter)}`);
7449
+ const res = await this.request(
7450
+ "GET",
7451
+ `${SANDBOXES}${listQuery(filter)}`
7452
+ );
7056
7453
  return res.sandboxes;
7057
7454
  }
7058
7455
  async read(sandboxId, filePath) {
@@ -7060,16 +7457,72 @@ var init_sandbox = __esm({
7060
7457
  "GET",
7061
7458
  `${SANDBOXES}/${sid(sandboxId)}/file?path=${encodeURIComponent(filePath)}`
7062
7459
  );
7063
- return { path: res.path, size: res.size, bytes: Buffer.from(res.contentBase64, "base64") };
7460
+ return {
7461
+ path: res.path,
7462
+ size: res.size,
7463
+ bytes: Buffer.from(res.contentBase64, "base64")
7464
+ };
7064
7465
  }
7065
- write(sandboxId, filePath, bytes) {
7066
- return this.request("PUT", `${SANDBOXES}/${sid(sandboxId)}/file`, {
7067
- path: filePath,
7068
- contentBase64: bytes.toString("base64")
7069
- });
7466
+ /** A file past one chunk goes up in parts under one upload id; the platform lands it whole once the last part's
7467
+ * size and SHA-256 check out. */
7468
+ async write(sandboxId, filePath, bytes) {
7469
+ if (bytes.length <= SANDBOX_WRITE_CHUNK_BYTES)
7470
+ return this.putFile(sandboxId, { path: filePath, contentBase64: bytes.toString("base64") });
7471
+ const whole = { upload: (0, import_node_crypto7.randomUUID)(), size: bytes.length, sha256: (0, import_node_crypto7.createHash)("sha256").update(bytes).digest("hex") };
7472
+ let answer = { path: filePath, received: 0 };
7473
+ for (let offset = 0; offset < bytes.length; offset += SANDBOX_WRITE_CHUNK_BYTES) {
7474
+ const part = bytes.subarray(offset, offset + SANDBOX_WRITE_CHUNK_BYTES);
7475
+ answer = await this.putFile(sandboxId, {
7476
+ path: filePath,
7477
+ contentBase64: part.toString("base64"),
7478
+ ...whole,
7479
+ offset,
7480
+ last: offset + part.length === bytes.length
7481
+ });
7482
+ }
7483
+ return answer;
7484
+ }
7485
+ putFile(sandboxId, body) {
7486
+ return this.request("PUT", `${SANDBOXES}/${sid(sandboxId)}/file`, body);
7487
+ }
7488
+ /** Runs as a job on the platform: a command that outlasts one request is waited on again until its result. */
7489
+ async exec(sandboxId, input) {
7490
+ const budgetMs = (input.timeoutMs ?? SANDBOX_EXEC_TIMEOUT_MAX_S * 1e3) + SANDBOX_EXEC_REPORT_MARGIN_MS;
7491
+ let answer = await this.startExec(sandboxId, { ...input, waitMs: SANDBOX_EXEC_WAIT_MS });
7492
+ const deadline = Date.now() + budgetMs;
7493
+ const warnings = [...answer.warnings ?? []];
7494
+ try {
7495
+ while ("state" in answer) {
7496
+ if (Date.now() >= deadline)
7497
+ throw new Error(
7498
+ `exec ${answer.execId} in sandbox ${sandboxId} has not reported back within ${budgetMs / 1e3} s, past its timeout: the sandbox may have restarted. Check the sandbox's status, then run the command again.`
7499
+ );
7500
+ answer = await this.execStep(sandboxId, { execId: answer.execId, waitMs: SANDBOX_EXEC_WAIT_MS });
7501
+ warnings.push(...answer.warnings ?? []);
7502
+ }
7503
+ } catch (error) {
7504
+ throw carrying(error, warnings);
7505
+ }
7506
+ return { ...answer, warnings };
7507
+ }
7508
+ // A deferred start ran nothing (the platform was still getting the sandbox ready), so starting again is safe. What
7509
+ // getting ready found rides on the deferral alone (no later call reports it), so it is kept for the answer, or for
7510
+ // the error when a later attempt fails.
7511
+ async startExec(sandboxId, body) {
7512
+ const kept = [];
7513
+ for (let attempt = 1; ; attempt += 1) {
7514
+ try {
7515
+ const answer = await this.execStep(sandboxId, body);
7516
+ return { ...answer, warnings: unique([...kept, ...answer.warnings ?? []]) };
7517
+ } catch (error) {
7518
+ const warnings = deferredWarnings(error);
7519
+ if (warnings === null || attempt === SANDBOX_EXEC_START_ATTEMPTS) throw carrying(error, kept);
7520
+ kept.push(...warnings);
7521
+ }
7522
+ }
7070
7523
  }
7071
- exec(sandboxId, input) {
7072
- return this.request("POST", `${SANDBOXES}/${sid(sandboxId)}/exec`, input);
7524
+ execStep(sandboxId, body) {
7525
+ return this.request("POST", `${SANDBOXES}/${sid(sandboxId)}/exec`, body);
7073
7526
  }
7074
7527
  check(sandboxId) {
7075
7528
  return this.request("POST", `${SANDBOXES}/${sid(sandboxId)}/check`, {});
@@ -7077,7 +7530,11 @@ var init_sandbox = __esm({
7077
7530
  /** With `rebase`, a moved base is replayed onto; a 409 then names the conflicting paths (`rebaseConflicts`). */
7078
7531
  commit(sandboxId, input) {
7079
7532
  const { rebase, ...rest } = input;
7080
- return this.request("POST", `${SANDBOXES}/${sid(sandboxId)}/commit`, rebase ? { ...rest, rebase: true } : rest);
7533
+ return this.request(
7534
+ "POST",
7535
+ `${SANDBOXES}/${sid(sandboxId)}/commit`,
7536
+ rebase ? { ...rest, rebase: true } : rest
7537
+ );
7081
7538
  }
7082
7539
  /**
7083
7540
  * A rows file already in the sandbox tree into the PLATFORM world the
@@ -7090,7 +7547,11 @@ var init_sandbox = __esm({
7090
7547
  }
7091
7548
  /** Uncommitted work is a 409 (`uncommittedPaths`) unless `force` discards it. */
7092
7549
  close(sandboxId, opts = {}) {
7093
- return this.request("DELETE", `${SANDBOXES}/${sid(sandboxId)}`, opts.force ? { force: true } : void 0);
7550
+ return this.request(
7551
+ "DELETE",
7552
+ `${SANDBOXES}/${sid(sandboxId)}`,
7553
+ opts.force ? { force: true } : void 0
7554
+ );
7094
7555
  }
7095
7556
  };
7096
7557
  }
@@ -7426,11 +7887,11 @@ function applyTransforms(value, chain) {
7426
7887
  for (const step of steps) out = step(out);
7427
7888
  return out;
7428
7889
  }
7429
- var import_node_crypto7, WHITESPACE, WHITESPACE_EDGES, WHITESPACE_RUN, NOT_DIGIT, STRIP_PREFIX, trim, emailLocalPart, emailDomain, stripPrefix, hex, SIMPLE, TRANSFORMS, text;
7890
+ var import_node_crypto8, WHITESPACE, WHITESPACE_EDGES, WHITESPACE_RUN, NOT_DIGIT, STRIP_PREFIX, trim, emailLocalPart, emailDomain, stripPrefix, hex, SIMPLE, TRANSFORMS, text;
7430
7891
  var init_transforms = __esm({
7431
7892
  "src/worlds/transforms.ts"() {
7432
7893
  "use strict";
7433
- import_node_crypto7 = require("crypto");
7894
+ import_node_crypto8 = require("crypto");
7434
7895
  init_json();
7435
7896
  WHITESPACE = " \n\r\f\v";
7436
7897
  WHITESPACE_EDGES = new RegExp(`^[${WHITESPACE}]+|[${WHITESPACE}]+$`, "g");
@@ -7447,7 +7908,7 @@ var init_transforms = __esm({
7447
7908
  return at === -1 ? "" : value.slice(at + 1).toLowerCase();
7448
7909
  };
7449
7910
  stripPrefix = (prefix) => (value) => value.startsWith(prefix) ? value.slice(prefix.length) : value;
7450
- hex = (algorithm, value) => (0, import_node_crypto7.createHash)(algorithm).update(value, "utf8").digest("hex");
7911
+ hex = (algorithm, value) => (0, import_node_crypto8.createHash)(algorithm).update(value, "utf8").digest("hex");
7451
7912
  SIMPLE = {
7452
7913
  lower: (value) => value.toLowerCase(),
7453
7914
  upper: (value) => value.toUpperCase(),
@@ -7479,7 +7940,7 @@ function pyText(value) {
7479
7940
  return pyFloatRepr(value);
7480
7941
  }
7481
7942
  function hashForm(slug, plaintext) {
7482
- return "sha256:" + (0, import_node_crypto8.createHash)("sha256").update(`${slug}:${pyText(plaintext)}`, "utf8").digest("hex");
7943
+ return "sha256:" + (0, import_node_crypto9.createHash)("sha256").update(`${slug}:${pyText(plaintext)}`, "utf8").digest("hex");
7483
7944
  }
7484
7945
  function preserveForm(slug, plaintext) {
7485
7946
  const kind = typeof plaintext === "string" ? "str" : isInt(plaintext) ? "int" : "float";
@@ -7488,12 +7949,12 @@ function preserveForm(slug, plaintext) {
7488
7949
  }
7489
7950
  function shapeText(slug, text2, kind) {
7490
7951
  const seed = Buffer.from(`${slug}:${text2}`, "utf8");
7491
- let digest = (0, import_node_crypto8.createHash)("sha256").update(seed).digest();
7952
+ let digest = (0, import_node_crypto9.createHash)("sha256").update(seed).digest();
7492
7953
  let cursor = 0;
7493
7954
  const out = [];
7494
7955
  for (const char of text2) {
7495
7956
  if (cursor === digest.length) {
7496
- digest = (0, import_node_crypto8.createHash)("sha256").update(Buffer.concat([digest, seed])).digest();
7957
+ digest = (0, import_node_crypto9.createHash)("sha256").update(Buffer.concat([digest, seed])).digest();
7497
7958
  cursor = 0;
7498
7959
  }
7499
7960
  const byte = digest[cursor];
@@ -7530,11 +7991,11 @@ function storedForms(world, field2, plaintext, transform) {
7530
7991
  if (policy !== null) return [roundForm(plaintext, world.redact.round[field2])];
7531
7992
  return [plaintext];
7532
7993
  }
7533
- var import_node_crypto8, isInt;
7994
+ var import_node_crypto9, isInt;
7534
7995
  var init_redaction = __esm({
7535
7996
  "src/worlds/redaction.ts"() {
7536
7997
  "use strict";
7537
- import_node_crypto8 = require("crypto");
7998
+ import_node_crypto9 = require("crypto");
7538
7999
  init_json();
7539
8000
  init_transforms();
7540
8001
  isInt = (value) => typeof value === "number" && Number.isInteger(value);
@@ -7647,7 +8108,7 @@ var init_config = __esm({
7647
8108
  init_transport();
7648
8109
  ApiError2 = class extends CliError {
7649
8110
  constructor(status, method, route, text2) {
7650
- const body = parseErrorBody(text2);
8111
+ const body = parseErrorBody(text2, status);
7651
8112
  super(`${method} ${route} -> ${status}: ${body.detail}`, 1);
7652
8113
  this.status = status;
7653
8114
  this.method = method;
@@ -7665,6 +8126,14 @@ var init_config = __esm({
7665
8126
  });
7666
8127
 
7667
8128
  // src/cli/runtime/local.ts
8129
+ function forwardedEnv() {
8130
+ return Object.fromEntries(
8131
+ FORWARDED_ENV.flatMap((name) => {
8132
+ const value = process.env[name];
8133
+ return value ? [[name, value]] : [];
8134
+ })
8135
+ );
8136
+ }
7668
8137
  function tailOf(output) {
7669
8138
  return output.length > DIAGNOSTIC_TAIL ? `\u2026${output.slice(-DIAGNOSTIC_TAIL)}` : output;
7670
8139
  }
@@ -7782,7 +8251,7 @@ async function localBridge(request, local, opts = {}) {
7782
8251
  PATH: process.env.PATH ?? "",
7783
8252
  HOME: process.env.HOME ?? "",
7784
8253
  TMPDIR: process.env.TMPDIR ?? "",
7785
- ...process.env.VIRTUAL_ENV ? { VIRTUAL_ENV: process.env.VIRTUAL_ENV } : {},
8254
+ ...forwardedEnv(),
7786
8255
  GATEWAY_RUNTIME_EXECUTE: "1"
7787
8256
  }
7788
8257
  }
@@ -7828,7 +8297,7 @@ async function localBridge(request, local, opts = {}) {
7828
8297
  child.stdin.end(input);
7829
8298
  });
7830
8299
  }
7831
- var import_node_child_process2, fs7, net, path8, MIN_PYTHON, MIN_PYTHON_LABEL, DIAGNOSTIC_TAIL, BRIDGE_BOOTSTRAP, pythonCache, pythonProbes, PYTHON_CANDIDATES, UV_FIND;
8300
+ var import_node_child_process2, fs7, net, path8, MIN_PYTHON, MIN_PYTHON_LABEL, DIAGNOSTIC_TAIL, FORWARDED_ENV, BRIDGE_BOOTSTRAP, pythonCache, pythonProbes, PYTHON_CANDIDATES, UV_FIND;
7832
8301
  var init_local = __esm({
7833
8302
  "src/cli/runtime/local.ts"() {
7834
8303
  "use strict";
@@ -7841,6 +8310,7 @@ var init_local = __esm({
7841
8310
  MIN_PYTHON = [3, 12];
7842
8311
  MIN_PYTHON_LABEL = MIN_PYTHON.join(".");
7843
8312
  DIAGNOSTIC_TAIL = 600;
8313
+ FORWARDED_ENV = ["VIRTUAL_ENV", "GATEWAY_SNAPSHOT_STORE"];
7844
8314
  BRIDGE_BOOTSTRAP = `import sys,runpy,types,os
7845
8315
  root=sys.argv[1]
7846
8316
  package=types.ModuleType('gatewaysdk')
@@ -8476,11 +8946,15 @@ function isSettled(status) {
8476
8946
  if (status.state !== "applied") return true;
8477
8947
  return status.dryRun === true || status.publish !== "now" || !status.snapshotId;
8478
8948
  }
8949
+ function worldDataPollMs() {
8950
+ const raw = Number(process.env.GATEWAY_WORLD_DATA_POLL_MS ?? 1e3);
8951
+ return Number.isFinite(raw) && raw >= 0 ? raw : 1e3;
8952
+ }
8479
8953
  function uploadHeadersFor(gz) {
8480
8954
  return {
8481
8955
  "content-type": "application/gzip",
8482
8956
  "content-length": String(gz.length),
8483
- "x-amz-checksum-sha256": (0, import_node_crypto9.createHash)("sha256").update(gz).digest("base64")
8957
+ "x-amz-checksum-sha256": (0, import_node_crypto10.createHash)("sha256").update(gz).digest("base64")
8484
8958
  };
8485
8959
  }
8486
8960
  async function forEachLimited(items, limit, fn) {
@@ -8518,6 +8992,8 @@ async function waitForBatch(client, batchId, opts = {}) {
8518
8992
  last = phase;
8519
8993
  }
8520
8994
  if (isSettled(status)) return status;
8995
+ if (opts.deadlineMs !== void 0 && (opts.now ?? Date.now)() >= opts.deadlineMs)
8996
+ return status;
8521
8997
  await sleep4(delay);
8522
8998
  delay = Math.min(1e4, Math.round(delay * 1.5));
8523
8999
  }
@@ -8526,11 +9002,11 @@ function phaseLine(status) {
8526
9002
  const phase = status.progress?.phase;
8527
9003
  return phase ? `${status.state} (${phase})` : status.state;
8528
9004
  }
8529
- var import_node_crypto9, fs11, TERMINAL_STATES, sleepMs, WorldDataApi;
9005
+ var import_node_crypto10, fs11, TERMINAL_STATES, sleepMs, WorldDataApi;
8530
9006
  var init_batches = __esm({
8531
9007
  "src/cli/platform/worldData/batches.ts"() {
8532
9008
  "use strict";
8533
- import_node_crypto9 = require("crypto");
9009
+ import_node_crypto10 = require("crypto");
8534
9010
  fs11 = __toESM(require("fs"));
8535
9011
  init_config();
8536
9012
  init_router();
@@ -8569,11 +9045,6 @@ var init_batches = __esm({
8569
9045
  }
8570
9046
  );
8571
9047
  }
8572
- /**
8573
- * Stage a project-drive rows file as one chunk, on the platform: the server
8574
- * streams it out of drive storage into chunk storage and answers with the
8575
- * digest and gzipped size it derived. No bytes pass through this process.
8576
- */
8577
9048
  async stageDrive(batchId, chunk) {
8578
9049
  const staged = await api(this.creds, "POST", `${this.base}/batches/${batchId}/chunks`, {
8579
9050
  ordinal: chunk.ordinal,
@@ -8627,11 +9098,6 @@ var init_batches = __esm({
8627
9098
  message ? { message } : {}
8628
9099
  );
8629
9100
  }
8630
- /**
8631
- * PUT the gzipped chunk to its presigned URL with exactly the headers the
8632
- * URL was signed for (the platform's `uploadHeaders`; the same three when it
8633
- * sends none), with backoff on a dropped connection or a 5xx.
8634
- */
8635
9101
  async put(uploadUrl, gz, signed) {
8636
9102
  const headers = signed ?? uploadHeadersFor(gz);
8637
9103
  const delays = [500, 1500, 4e3];
@@ -8658,7 +9124,6 @@ var init_batches = __esm({
8658
9124
  await this.sleep(delays[attempt]);
8659
9125
  }
8660
9126
  }
8661
- /** Register, upload unless the server already holds the content, confirm. */
8662
9127
  async upload(batchId, chunk) {
8663
9128
  const registered = await this.register(batchId, chunk);
8664
9129
  if (!registered.uploaded) {
@@ -8724,12 +9189,12 @@ function finishChunk(ordinal, raw, rows, entity, firstRow = 0) {
8724
9189
  const gz = gzipDeterministic(raw, { name: chunkName(ordinal) });
8725
9190
  return {
8726
9191
  ordinal,
8727
- digest: (0, import_node_crypto10.createHash)("sha256").update(gz).digest("hex"),
9192
+ digest: (0, import_node_crypto11.createHash)("sha256").update(gz).digest("hex"),
8728
9193
  bytes: gz.length,
8729
9194
  rows,
8730
9195
  entity,
8731
9196
  rawBytes: raw.length,
8732
- contentSha256: (0, import_node_crypto10.createHash)("sha256").update(raw).digest("hex"),
9197
+ contentSha256: (0, import_node_crypto11.createHash)("sha256").update(raw).digest("hex"),
8733
9198
  firstRow,
8734
9199
  gz
8735
9200
  };
@@ -8769,11 +9234,11 @@ function crc32(data) {
8769
9234
  crc = table[(crc ^ data[i]) & 255] ^ crc >>> 8;
8770
9235
  return (crc ^ 4294967295) >>> 0;
8771
9236
  }
8772
- var import_node_crypto10, import_node_zlib3, DEFAULT_CHUNK_BYTES, GZIP_LEVEL, chunkName, table;
9237
+ var import_node_crypto11, import_node_zlib3, DEFAULT_CHUNK_BYTES, GZIP_LEVEL, chunkName, table;
8773
9238
  var init_chunker = __esm({
8774
9239
  "src/cli/platform/worldData/chunker.ts"() {
8775
9240
  "use strict";
8776
- import_node_crypto10 = require("crypto");
9241
+ import_node_crypto11 = require("crypto");
8777
9242
  import_node_zlib3 = require("zlib");
8778
9243
  init_json();
8779
9244
  DEFAULT_CHUNK_BYTES = 64 * 1024 * 1024;
@@ -8799,22 +9264,33 @@ async function pushRows(creds, slug, rows, opts = {}) {
8799
9264
  publish: opts.publish ?? "now",
8800
9265
  ...opts.message ? { message: opts.message } : {}
8801
9266
  });
8802
- if (!opened.batchId) throw new Error("the platform opened no batch (no batchId in the answer)");
9267
+ if (!opened.batchId)
9268
+ throw new Error("the platform opened no batch (no batchId in the answer)");
8803
9269
  const tagged = (async function* () {
8804
9270
  for (const [entity, listed] of Object.entries(rows))
8805
9271
  for (let index = 0; index < listed.length; index++)
8806
- yield { entity, row: parseJson(JSON.stringify(listed[index])), where: `${entity}[${index}]` };
9272
+ yield {
9273
+ entity,
9274
+ row: parseJson(JSON.stringify(listed[index])),
9275
+ where: `${entity}[${index}]`
9276
+ };
8807
9277
  })();
8808
- const chunks = buildChunks(tagged, { chunkBytes: opts.chunkBytes ?? DEFAULT_CHUNK_BYTES, chunkRows: null, entity: null });
8809
- await forEachLimited(chunks, Math.max(1, opts.parallel ?? 4), async (chunk) => {
8810
- await client.upload(opened.batchId, chunk);
9278
+ const chunks = buildChunks(tagged, {
9279
+ chunkBytes: opts.chunkBytes ?? DEFAULT_CHUNK_BYTES,
9280
+ chunkRows: null,
9281
+ entity: null
8811
9282
  });
9283
+ await forEachLimited(
9284
+ chunks,
9285
+ Math.max(1, opts.parallel ?? 4),
9286
+ async (chunk) => {
9287
+ await client.upload(opened.batchId, chunk);
9288
+ }
9289
+ );
8812
9290
  await client.complete(opened.batchId);
8813
- return waitForBatch(client, opened.batchId, { initialDelayMs: pollMs() });
8814
- }
8815
- function pollMs() {
8816
- const raw = Number(process.env.GATEWAY_WORLD_DATA_POLL_MS ?? 1e3);
8817
- return Number.isFinite(raw) && raw >= 0 ? raw : 1e3;
9291
+ return waitForBatch(client, opened.batchId, {
9292
+ initialDelayMs: worldDataPollMs()
9293
+ });
8818
9294
  }
8819
9295
  var init_push = __esm({
8820
9296
  "src/cli/platform/worldData/push.ts"() {
@@ -9063,12 +9539,12 @@ var init_ingest = __esm({
9063
9539
  });
9064
9540
 
9065
9541
  // src/worlds/editSessions.ts
9066
- var WORLDS, WorldEditClient, TASK_EDITS, TaskEditClient;
9542
+ var WORLDS2, WorldEditClient, TASK_EDITS, TaskEditClient;
9067
9543
  var init_editSessions = __esm({
9068
9544
  "src/worlds/editSessions.ts"() {
9069
9545
  "use strict";
9070
9546
  init_worlds();
9071
- WORLDS = "/api/public/worlds";
9547
+ WORLDS2 = "/api/public/worlds";
9072
9548
  WorldEditClient = class {
9073
9549
  constructor(options = {}) {
9074
9550
  this.options = options;
@@ -9080,19 +9556,19 @@ var init_editSessions = __esm({
9080
9556
  if (query.status) qs.set("status", query.status);
9081
9557
  if (query.limit !== void 0) qs.set("limit", String(query.limit));
9082
9558
  const suffix = qs.size ? `?${qs.toString()}` : "";
9083
- return apiRequest(this.options, "GET", `${WORLDS}/${encodeURIComponent(slug)}/edits${suffix}`);
9559
+ return apiRequest(this.options, "GET", `${WORLDS2}/${encodeURIComponent(slug)}/edits${suffix}`);
9084
9560
  }
9085
9561
  /** Seal a session into a version on main (the credential's current one when `sessionId` is omitted). */
9086
9562
  close(slug, input = {}) {
9087
- return apiRequest(this.options, "POST", `${WORLDS}/${encodeURIComponent(slug)}/edits/close`, input);
9563
+ return apiRequest(this.options, "POST", `${WORLDS2}/${encodeURIComponent(slug)}/edits/close`, input);
9088
9564
  }
9089
9565
  /** Drop the session's private branch without making a version. */
9090
9566
  discard(slug, input = {}) {
9091
- return apiRequest(this.options, "POST", `${WORLDS}/${encodeURIComponent(slug)}/edits/discard`, input);
9567
+ return apiRequest(this.options, "POST", `${WORLDS2}/${encodeURIComponent(slug)}/edits/discard`, input);
9092
9568
  }
9093
9569
  /** Undo a sealed session (source and data) as a new sealed session. */
9094
9570
  rollback(slug, input) {
9095
- return apiRequest(this.options, "POST", `${WORLDS}/${encodeURIComponent(slug)}/edits/rollback`, input);
9571
+ return apiRequest(this.options, "POST", `${WORLDS2}/${encodeURIComponent(slug)}/edits/rollback`, input);
9096
9572
  }
9097
9573
  };
9098
9574
  TASK_EDITS = "/api/public/world-task-edits";
@@ -9246,15 +9722,27 @@ __export(worlds_exports, {
9246
9722
  NativeComputer: () => NativeComputer,
9247
9723
  OpenAIComputer: () => OpenAIComputer,
9248
9724
  OpenAIPreviewComputer: () => OpenAIPreviewComputer,
9725
+ PLATFORM_SESSION_HEADER: () => PLATFORM_SESSION_HEADER,
9249
9726
  PLATFORM_TIMEOUT_DEFAULT_MS: () => PLATFORM_TIMEOUT_DEFAULT_MS,
9250
9727
  PLATFORM_TIMEOUT_ENV: () => PLATFORM_TIMEOUT_ENV,
9251
9728
  PendingSafetyChecks: () => PendingSafetyChecks,
9252
9729
  PlatformTransport: () => PlatformTransport,
9253
9730
  PushSlugConflict: () => PushSlugConflict,
9254
9731
  RECOVER_BUDGET_MS: () => RECOVER_BUDGET_MS,
9732
+ REQUESTS_NOT_RECORDED: () => REQUESTS_NOT_RECORDED,
9733
+ REQUEST_BODY_CAPTURE_BYTES: () => REQUEST_BODY_CAPTURE_BYTES,
9734
+ REQUEST_LOG_PAGE_MAX: () => REQUEST_LOG_PAGE_MAX,
9255
9735
  RetryPolicy: () => RetryPolicy,
9736
+ SANDBOX_EXEC_REPORT_MARGIN_MS: () => SANDBOX_EXEC_REPORT_MARGIN_MS,
9737
+ SANDBOX_EXEC_START_ATTEMPTS: () => SANDBOX_EXEC_START_ATTEMPTS,
9738
+ SANDBOX_EXEC_TIMEOUT_MAX_S: () => SANDBOX_EXEC_TIMEOUT_MAX_S,
9739
+ SANDBOX_EXEC_WAIT_MS: () => SANDBOX_EXEC_WAIT_MS,
9740
+ SANDBOX_FILE_MAX_BYTES: () => SANDBOX_FILE_MAX_BYTES,
9256
9741
  SANDBOX_REQUEST_TIMEOUT_MS: () => SANDBOX_REQUEST_TIMEOUT_MS,
9742
+ SANDBOX_WRITE_CHUNK_BYTES: () => SANDBOX_WRITE_CHUNK_BYTES,
9743
+ SANDBOX_WRITE_SKIPPED: () => SANDBOX_WRITE_SKIPPED,
9257
9744
  SECRET_KEY: () => SECRET_KEY,
9745
+ SESSION_AUTH_MODES: () => SESSION_AUTH_MODES,
9258
9746
  SESSION_STATES: () => SESSION_STATES,
9259
9747
  SPAN_PREFIX: () => SPAN_PREFIX,
9260
9748
  STATUS_WAIT_CAP_SECONDS: () => STATUS_WAIT_CAP_SECONDS,
@@ -9266,17 +9754,23 @@ __export(worlds_exports, {
9266
9754
  TOOL_CONTRACT_UNREAD: () => TOOL_CONTRACT_UNREAD,
9267
9755
  TRANSFORMS: () => TRANSFORMS,
9268
9756
  TaskEditClient: () => TaskEditClient,
9757
+ TaskGrades: () => TaskGrades,
9269
9758
  TaskRun: () => TaskRun,
9270
9759
  TaskSessions: () => TaskSessions,
9271
9760
  TransportCause: () => TransportCause,
9272
9761
  UnreachableError: () => UnreachableError,
9273
9762
  VERIFIER_REWARD_PREFIX: () => VERIFIER_REWARD_PREFIX,
9274
9763
  WHITESPACE: () => WHITESPACE,
9764
+ WORLD_REQUEST_VIAS: () => WORLD_REQUEST_VIAS,
9275
9765
  WorldBrowser: () => WorldBrowser,
9276
9766
  WorldCallTooLarge: () => WorldCallTooLarge,
9277
9767
  WorldEditClient: () => WorldEditClient,
9278
9768
  WorldNotice: () => WorldNotice,
9769
+ WorldRequestFilterError: () => WorldRequestFilterError,
9770
+ WorldRequestLedger: () => WorldRequestLedger,
9279
9771
  WorldRequestLog: () => WorldRequestLog,
9772
+ WorldRequestQuery: () => WorldRequestQuery,
9773
+ WorldRequestsNotRecorded: () => WorldRequestsNotRecorded,
9280
9774
  WorldSandboxClient: () => WorldSandboxClient,
9281
9775
  WorldSession: () => WorldSession,
9282
9776
  WorldSessionCallError: () => WorldSessionCallError,
@@ -9286,18 +9780,22 @@ __export(worlds_exports, {
9286
9780
  WorldSurfaceUnavailable: () => WorldSurfaceUnavailable,
9287
9781
  WorldTask: () => WorldTask,
9288
9782
  WorldToolsUnread: () => WorldToolsUnread,
9783
+ WriteTreeFilter: () => WriteTreeFilter,
9289
9784
  aggregateTaskGrade: () => aggregateTaskGrade,
9290
9785
  apiRequest: () => apiRequest,
9291
9786
  applyTransforms: () => applyTransforms,
9292
9787
  archiveMode: () => archiveMode,
9293
9788
  assertBrowserTier: () => assertBrowserTier,
9789
+ assertSessionAuthMode: () => assertSessionAuthMode,
9294
9790
  assertTaskRef: () => assertTaskRef,
9295
9791
  attachManifest: () => attachManifest,
9296
9792
  attachSession: () => attachSession,
9297
9793
  attachTask: () => attachTask,
9298
9794
  buildFileManifest: () => buildFileManifest,
9299
9795
  buildSourceTarball: () => buildSourceTarball,
9796
+ capabilityLabel: () => capabilityLabel,
9300
9797
  captureToolCalls: () => captureToolCalls,
9798
+ carriedWarnings: () => carriedWarnings,
9301
9799
  checkoutIdentity: () => checkoutIdentity,
9302
9800
  closeConnection: () => closeConnection,
9303
9801
  collectArchiveRelPaths: () => collectArchiveRelPaths,
@@ -9316,7 +9814,9 @@ __export(worlds_exports, {
9316
9814
  idleWarning: () => idleWarning,
9317
9815
  ingest: () => ingest,
9318
9816
  ingestToolCalls: () => ingestToolCalls,
9817
+ invalidFields: () => invalidFields,
9319
9818
  isBrowserGone: () => isBrowserGone,
9819
+ isSandboxCommitPending: () => isSandboxCommitPending,
9320
9820
  isSandboxImportPending: () => isSandboxImportPending,
9321
9821
  isTaskIdRef: () => isTaskIdRef,
9322
9822
  isTaskManifest: () => isTaskManifest,
@@ -9363,6 +9863,7 @@ __export(worlds_exports, {
9363
9863
  resolveBrowserMode: () => resolveBrowserMode,
9364
9864
  resolvePushSlug: () => resolvePushSlug,
9365
9865
  roundForm: () => roundForm,
9866
+ rowsRefusal: () => rowsRefusal,
9366
9867
  runSessions: () => runSessions,
9367
9868
  runSet: () => runSet,
9368
9869
  runTask: () => runTask,
@@ -9391,28 +9892,43 @@ __export(worlds_exports, {
9391
9892
  validateWorld: () => validateWorld,
9392
9893
  waitForRun: () => waitForRun,
9393
9894
  withoutUiToken: () => withoutUiToken,
9895
+ worldRequestsUnrecorded: () => worldRequestsUnrecorded,
9394
9896
  writeLocalMeta: () => writeLocalMeta
9395
9897
  });
9396
9898
  module.exports = __toCommonJS(worlds_exports);
9397
- function parseErrorBody(text2, limit = 600) {
9398
- const raw = { detail: text2.slice(0, limit), code: null };
9899
+ function edgeAnswer(text2, status) {
9900
+ if (status !== void 0 && status >= 500) return EDGE_ANSWERS[status] ?? EDGE_FAILURE;
9901
+ return /^\s*</.test(text2) ? EDGE_PAGE : null;
9902
+ }
9903
+ function parseErrorBody(text2, status) {
9904
+ const raw = { detail: text2.slice(0, DETAIL_LIMIT), code: null };
9399
9905
  let parsed;
9400
9906
  try {
9401
9907
  parsed = JSON.parse(text2);
9402
9908
  } catch {
9403
- return raw;
9909
+ return { detail: (edgeAnswer(text2, status) ?? text2).slice(0, DETAIL_LIMIT), code: null };
9404
9910
  }
9405
9911
  if (parsed === null || typeof parsed !== "object") return raw;
9406
- const { message, code } = parsed;
9912
+ const { message, code, error } = parsed;
9407
9913
  const stableCode = typeof code === "string" ? code : null;
9408
9914
  if (typeof message !== "string") return { ...raw, code: stableCode };
9409
- if (stableCode === null)
9410
- return { detail: message.slice(0, limit), code: null };
9915
+ const fields = invalidFields(error);
9916
+ const said = fields ? `${message}: ${fields}` : message;
9917
+ if (stableCode === null) return { detail: said.slice(0, DETAIL_LIMIT), code: null };
9411
9918
  return {
9412
- detail: `${message} (${stableCode})`.slice(0, limit),
9919
+ detail: `${said} (${stableCode})`.slice(0, DETAIL_LIMIT),
9413
9920
  code: stableCode
9414
9921
  };
9415
9922
  }
9923
+ function invalidFields(error) {
9924
+ const issues = Array.isArray(error) ? error : [];
9925
+ return issues.filter(
9926
+ (issue) => issue !== null && typeof issue === "object" && typeof issue.message === "string"
9927
+ ).map((issue) => {
9928
+ const path13 = Array.isArray(issue.path) ? issue.path.map(String).join(".") : "";
9929
+ return path13 ? `${path13}: ${issue.message}` : issue.message;
9930
+ }).join("; ");
9931
+ }
9416
9932
  async function apiRequest(options, method, path13, body, init2 = {}) {
9417
9933
  const reply = await new PlatformTransport(requirePlatformEndpoint(options)).send(method, path13, body, init2);
9418
9934
  if (!reply.ok) throw new ApiError(reply.status, method, path13, reply.text);
@@ -9591,7 +10107,7 @@ async function resolveWorld(slugRef, slug, ref, pin, options) {
9591
10107
  }
9592
10108
  return world;
9593
10109
  }
9594
- var ApiError, WorldTask, WorldSet;
10110
+ var ApiError, DETAIL_LIMIT, EDGE_ANSWERS, EDGE_FAILURE, EDGE_PAGE, WorldTask, WorldSet;
9595
10111
  var init_worlds = __esm({
9596
10112
  "src/worlds/index.ts"() {
9597
10113
  init_platformEndpoint();
@@ -9603,6 +10119,7 @@ var init_worlds = __esm({
9603
10119
  init_sessionContract();
9604
10120
  init_taskRef();
9605
10121
  init_tasks();
10122
+ init_taskGrades();
9606
10123
  init_taskSessions();
9607
10124
  init_taskRun();
9608
10125
  init_setRun();
@@ -9611,6 +10128,7 @@ var init_worlds = __esm({
9611
10128
  init_browser();
9612
10129
  init_surfaceDescriptor();
9613
10130
  init_requestLog();
10131
+ init_requestLedger();
9614
10132
  init_browserReconnect();
9615
10133
  init_nativeComputer();
9616
10134
  init_hub();
@@ -9627,7 +10145,7 @@ var init_worlds = __esm({
9627
10145
  init_worldNotice();
9628
10146
  ApiError = class extends Error {
9629
10147
  constructor(status, method, path13, text2) {
9630
- const parsed = parseErrorBody(text2);
10148
+ const parsed = parseErrorBody(text2, status);
9631
10149
  super(`${method} ${path13} -> ${status}: ${parsed.detail}`);
9632
10150
  this.status = status;
9633
10151
  this.text = text2;
@@ -9638,6 +10156,14 @@ var init_worlds = __esm({
9638
10156
  text;
9639
10157
  code;
9640
10158
  };
10159
+ DETAIL_LIMIT = 600;
10160
+ EDGE_ANSWERS = {
10161
+ 502: "Bad Gateway from the load balancer in front of the platform, not the platform's answer: the web server dropped the connection or restarted mid-request. Retry; if it repeats, the platform is restarting or overloaded.",
10162
+ 503: "Service Unavailable from the load balancer in front of the platform, not the platform's answer: no web server was ready to take the request (a deploy or a restart). Retry in a minute.",
10163
+ 504: "Gateway Time-out from the load balancer in front of the platform, not the platform's answer: the request sent nothing back within the load balancer's idle timeout (60 s unless the deployment raises it: Helm ingress.idleTimeoutSeconds) and was cut there, though the platform may still be running it. Check what it changed before you retry."
10164
+ };
10165
+ EDGE_FAILURE = "The platform failed without its JSON error body: a proxy in front of it answered, or the server stopped before its error handler ran. Retry; if it repeats, report the request and the time.";
10166
+ EDGE_PAGE = "An HTML page answered instead of the platform's JSON: a proxy in front of the platform, or the configured host is not the platform.";
9641
10167
  WorldTask = class {
9642
10168
  constructor(world, name, variant) {
9643
10169
  this.world = world;
@@ -9673,12 +10199,7 @@ var init_worlds = __esm({
9673
10199
  }
9674
10200
  return hit;
9675
10201
  }
9676
- /**
9677
- * Open a LIVE session against one of this world's tasks — a bundled task's
9678
- * name or an inline `WorldTaskSpec`: the platform boots (or reuses) a warm
9679
- * container, and your agent calls its tools through the platform. See
9680
- * worlds/session.ts.
9681
- */
10202
+ /** Open a live session on a bundled task's name or an inline `WorldTaskSpec`; the platform boots or reuses a warm container. */
9682
10203
  async open(task, opts = {}) {
9683
10204
  const { openSession: openSession2 } = await Promise.resolve().then(() => (init_session2(), session_exports2));
9684
10205
  return openSession2(this.slug, {
@@ -9690,11 +10211,7 @@ var init_worlds = __esm({
9690
10211
  options: this.options
9691
10212
  });
9692
10213
  }
9693
- /**
9694
- * Start a HOSTED run of a run config against this world — the platform
9695
- * executes the (Python) world in parallel containers per the config's
9696
- * `parallelism` and files one graded run per model. Returns those runs.
9697
- */
10214
+ /** Start a hosted run of a run config on this version (or `opts.versionId`): one graded run per model, provenance detected unless given. */
9698
10215
  async dispatch(runConfigId, opts = {}) {
9699
10216
  const provenance = opts.provenance ?? detectProvenance();
9700
10217
  return apiRequest(
@@ -9755,15 +10272,27 @@ init_worlds();
9755
10272
  NativeComputer,
9756
10273
  OpenAIComputer,
9757
10274
  OpenAIPreviewComputer,
10275
+ PLATFORM_SESSION_HEADER,
9758
10276
  PLATFORM_TIMEOUT_DEFAULT_MS,
9759
10277
  PLATFORM_TIMEOUT_ENV,
9760
10278
  PendingSafetyChecks,
9761
10279
  PlatformTransport,
9762
10280
  PushSlugConflict,
9763
10281
  RECOVER_BUDGET_MS,
10282
+ REQUESTS_NOT_RECORDED,
10283
+ REQUEST_BODY_CAPTURE_BYTES,
10284
+ REQUEST_LOG_PAGE_MAX,
9764
10285
  RetryPolicy,
10286
+ SANDBOX_EXEC_REPORT_MARGIN_MS,
10287
+ SANDBOX_EXEC_START_ATTEMPTS,
10288
+ SANDBOX_EXEC_TIMEOUT_MAX_S,
10289
+ SANDBOX_EXEC_WAIT_MS,
10290
+ SANDBOX_FILE_MAX_BYTES,
9765
10291
  SANDBOX_REQUEST_TIMEOUT_MS,
10292
+ SANDBOX_WRITE_CHUNK_BYTES,
10293
+ SANDBOX_WRITE_SKIPPED,
9766
10294
  SECRET_KEY,
10295
+ SESSION_AUTH_MODES,
9767
10296
  SESSION_STATES,
9768
10297
  SPAN_PREFIX,
9769
10298
  STATUS_WAIT_CAP_SECONDS,
@@ -9775,17 +10304,23 @@ init_worlds();
9775
10304
  TOOL_CONTRACT_UNREAD,
9776
10305
  TRANSFORMS,
9777
10306
  TaskEditClient,
10307
+ TaskGrades,
9778
10308
  TaskRun,
9779
10309
  TaskSessions,
9780
10310
  TransportCause,
9781
10311
  UnreachableError,
9782
10312
  VERIFIER_REWARD_PREFIX,
9783
10313
  WHITESPACE,
10314
+ WORLD_REQUEST_VIAS,
9784
10315
  WorldBrowser,
9785
10316
  WorldCallTooLarge,
9786
10317
  WorldEditClient,
9787
10318
  WorldNotice,
10319
+ WorldRequestFilterError,
10320
+ WorldRequestLedger,
9788
10321
  WorldRequestLog,
10322
+ WorldRequestQuery,
10323
+ WorldRequestsNotRecorded,
9789
10324
  WorldSandboxClient,
9790
10325
  WorldSession,
9791
10326
  WorldSessionCallError,
@@ -9795,18 +10330,22 @@ init_worlds();
9795
10330
  WorldSurfaceUnavailable,
9796
10331
  WorldTask,
9797
10332
  WorldToolsUnread,
10333
+ WriteTreeFilter,
9798
10334
  aggregateTaskGrade,
9799
10335
  apiRequest,
9800
10336
  applyTransforms,
9801
10337
  archiveMode,
9802
10338
  assertBrowserTier,
10339
+ assertSessionAuthMode,
9803
10340
  assertTaskRef,
9804
10341
  attachManifest,
9805
10342
  attachSession,
9806
10343
  attachTask,
9807
10344
  buildFileManifest,
9808
10345
  buildSourceTarball,
10346
+ capabilityLabel,
9809
10347
  captureToolCalls,
10348
+ carriedWarnings,
9810
10349
  checkoutIdentity,
9811
10350
  closeConnection,
9812
10351
  collectArchiveRelPaths,
@@ -9825,7 +10364,9 @@ init_worlds();
9825
10364
  idleWarning,
9826
10365
  ingest,
9827
10366
  ingestToolCalls,
10367
+ invalidFields,
9828
10368
  isBrowserGone,
10369
+ isSandboxCommitPending,
9829
10370
  isSandboxImportPending,
9830
10371
  isTaskIdRef,
9831
10372
  isTaskManifest,
@@ -9872,6 +10413,7 @@ init_worlds();
9872
10413
  resolveBrowserMode,
9873
10414
  resolvePushSlug,
9874
10415
  roundForm,
10416
+ rowsRefusal,
9875
10417
  runSessions,
9876
10418
  runSet,
9877
10419
  runTask,
@@ -9900,6 +10442,7 @@ init_worlds();
9900
10442
  validateWorld,
9901
10443
  waitForRun,
9902
10444
  withoutUiToken,
10445
+ worldRequestsUnrecorded,
9903
10446
  writeLocalMeta
9904
10447
  });
9905
10448
  //# sourceMappingURL=index.js.map