@withgateway/sdk 0.3.1 → 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 (176) hide show
  1. package/README.md +8 -6
  2. package/dist/cli.js +4372 -2265
  3. package/dist/cli.js.map +1 -1
  4. package/dist/cli.mjs +4362 -2256
  5. package/dist/cli.mjs.map +1 -1
  6. package/dist/files/index.d.mts +1 -1
  7. package/dist/files/index.d.ts +1 -1
  8. package/dist/files/index.js +259 -58
  9. package/dist/files/index.js.map +1 -1
  10. package/dist/files/index.mjs +249 -50
  11. package/dist/files/index.mjs.map +1 -1
  12. package/dist/hooks/index.d.mts +1 -1
  13. package/dist/hooks/index.d.ts +1 -1
  14. package/dist/hooks/index.js +124 -11
  15. package/dist/hooks/index.js.map +1 -1
  16. package/dist/hooks/index.mjs +124 -11
  17. package/dist/hooks/index.mjs.map +1 -1
  18. package/dist/{index-C3UzD0G3.d.mts → index-CDPQBsU5.d.mts} +19 -3
  19. package/dist/{index-C3UzD0G3.d.ts → index-CDPQBsU5.d.ts} +19 -3
  20. package/dist/{index-CBqbB_0J.d.ts → index-DUHmS74p.d.ts} +1 -1
  21. package/dist/{index-D-AMnAMa.d.mts → index-mJhG3vZU.d.mts} +1 -1
  22. package/dist/index.d.mts +5 -5
  23. package/dist/index.d.ts +5 -5
  24. package/dist/index.js +2240 -789
  25. package/dist/index.js.map +1 -1
  26. package/dist/index.mjs +2150 -739
  27. package/dist/index.mjs.map +1 -1
  28. package/dist/{media-CbcAfQvd.d.mts → media-BIApiPzS.d.mts} +21 -2
  29. package/dist/{media-CbcAfQvd.d.ts → media-BIApiPzS.d.ts} +21 -2
  30. package/dist/traces/index.d.mts +1 -1
  31. package/dist/traces/index.d.ts +1 -1
  32. package/dist/traces/index.js +253 -52
  33. package/dist/traces/index.js.map +1 -1
  34. package/dist/traces/index.mjs +243 -44
  35. package/dist/traces/index.mjs.map +1 -1
  36. package/dist/tracing/index.d.mts +2 -2
  37. package/dist/tracing/index.d.ts +2 -2
  38. package/dist/tracing/index.js +75 -13
  39. package/dist/tracing/index.js.map +1 -1
  40. package/dist/tracing/index.mjs +75 -13
  41. package/dist/tracing/index.mjs.map +1 -1
  42. package/dist/worlds/index.d.mts +893 -482
  43. package/dist/worlds/index.d.ts +893 -482
  44. package/dist/worlds/index.js +1968 -669
  45. package/dist/worlds/index.js.map +1 -1
  46. package/dist/worlds/index.mjs +1960 -662
  47. package/dist/worlds/index.mjs.map +1 -1
  48. package/package.json +1 -1
  49. package/runtime/gatewaysdk/environment/_bundle.py +2 -27
  50. package/runtime/gatewaysdk/environment/_materialize.py +48 -88
  51. package/runtime/gatewaysdk/environment/_world.py +155 -237
  52. package/runtime/gatewaysdk/environment/backing.py +133 -0
  53. package/runtime/gatewaysdk/environment/core.py +2 -17
  54. package/runtime/gatewaysdk/environment/legacy_sqlite.py +288 -0
  55. package/runtime/gatewaysdk/environment/reward_keys.py +25 -0
  56. package/runtime/gatewaysdk/environment/runtime.py +8 -13
  57. package/runtime/gatewaysdk/environment/schema/__init__.py +4 -4
  58. package/runtime/gatewaysdk/environment/schema/admin_routes.py +86 -0
  59. package/runtime/gatewaysdk/environment/schema/admission.py +174 -0
  60. package/runtime/gatewaysdk/environment/schema/api.py +347 -892
  61. package/runtime/gatewaysdk/environment/schema/assertions.py +458 -0
  62. package/runtime/gatewaysdk/environment/schema/batch.py +44 -39
  63. package/runtime/gatewaysdk/environment/schema/bundle_runtime.py +17 -5
  64. package/runtime/gatewaysdk/environment/schema/cache_layout.py +5 -0
  65. package/runtime/gatewaysdk/environment/schema/call_capture.py +309 -0
  66. package/runtime/gatewaysdk/environment/schema/call_log.py +503 -0
  67. package/runtime/gatewaysdk/environment/schema/call_redaction.py +526 -0
  68. package/runtime/gatewaysdk/environment/schema/cast.py +15 -35
  69. package/runtime/gatewaysdk/environment/schema/compiler.py +334 -158
  70. package/runtime/gatewaysdk/environment/schema/conform.py +14 -39
  71. package/runtime/gatewaysdk/environment/schema/connector.py +113 -211
  72. package/runtime/gatewaysdk/environment/schema/connectors/confluence/connector.toml +1 -12
  73. package/runtime/gatewaysdk/environment/schema/connectors/github/connector.toml +1 -0
  74. package/runtime/gatewaysdk/environment/schema/connectors/servicenow/connector.toml +2 -5
  75. package/runtime/gatewaysdk/environment/schema/cors.py +54 -0
  76. package/runtime/gatewaysdk/environment/schema/credentials.py +313 -8
  77. package/runtime/gatewaysdk/environment/schema/data.py +60 -216
  78. package/runtime/gatewaysdk/environment/schema/database/__init__.py +24 -0
  79. package/runtime/gatewaysdk/environment/schema/database/audit.py +121 -0
  80. package/runtime/gatewaysdk/environment/schema/database/base.py +936 -0
  81. package/runtime/gatewaysdk/environment/schema/database/budget.py +33 -0
  82. package/runtime/gatewaysdk/environment/schema/database/connections.py +101 -0
  83. package/runtime/gatewaysdk/environment/schema/database/engines.py +8 -0
  84. package/runtime/gatewaysdk/environment/schema/database/guard.py +215 -0
  85. package/runtime/gatewaysdk/environment/schema/database/ingest.py +154 -0
  86. package/runtime/gatewaysdk/environment/schema/database/matching.py +58 -0
  87. package/runtime/gatewaysdk/environment/schema/database/provenance.py +30 -0
  88. package/runtime/gatewaysdk/environment/schema/database/reads.py +169 -0
  89. package/runtime/gatewaysdk/environment/schema/database/rows.py +53 -0
  90. package/runtime/gatewaysdk/environment/schema/database/runtime_rows.py +39 -0
  91. package/runtime/gatewaysdk/environment/schema/database/sqlite.py +393 -0
  92. package/runtime/gatewaysdk/environment/schema/declared_routes.py +210 -0
  93. package/runtime/gatewaysdk/environment/schema/domain_migration.py +236 -0
  94. package/runtime/gatewaysdk/environment/schema/door.py +899 -0
  95. package/runtime/gatewaysdk/environment/schema/envelope.py +227 -0
  96. package/runtime/gatewaysdk/environment/schema/extract.py +6 -13
  97. package/runtime/gatewaysdk/environment/schema/grading.py +90 -103
  98. package/runtime/gatewaysdk/environment/schema/handler_errors.py +163 -12
  99. package/runtime/gatewaysdk/environment/schema/host.py +237 -1795
  100. package/runtime/gatewaysdk/environment/schema/host_control.py +144 -0
  101. package/runtime/gatewaysdk/environment/schema/host_handoff.py +370 -0
  102. package/runtime/gatewaysdk/environment/schema/host_loops.py +97 -0
  103. package/runtime/gatewaysdk/environment/schema/host_owners.py +121 -0
  104. package/runtime/gatewaysdk/environment/schema/host_proxy.py +111 -0
  105. package/runtime/gatewaysdk/environment/schema/host_requests.py +6 -0
  106. package/runtime/gatewaysdk/environment/schema/host_session.py +126 -0
  107. package/runtime/gatewaysdk/environment/schema/host_surfaces.py +79 -21
  108. package/runtime/gatewaysdk/environment/schema/host_transfers.py +127 -0
  109. package/runtime/gatewaysdk/environment/schema/host_versions.py +242 -0
  110. package/runtime/gatewaysdk/environment/schema/host_workers.py +577 -0
  111. package/runtime/gatewaysdk/environment/schema/journal.py +437 -0
  112. package/runtime/gatewaysdk/environment/schema/lanes.py +53 -0
  113. package/runtime/gatewaysdk/environment/schema/ledger_spill.py +828 -0
  114. package/runtime/gatewaysdk/environment/schema/local.py +58 -170
  115. package/runtime/gatewaysdk/environment/schema/mapping.py +5 -25
  116. package/runtime/gatewaysdk/environment/schema/openapi_import.py +112 -73
  117. package/runtime/gatewaysdk/environment/schema/openapi_paging.py +147 -0
  118. package/runtime/gatewaysdk/environment/schema/openapi_payloads.py +288 -0
  119. package/runtime/gatewaysdk/environment/schema/openapi_routes.py +97 -102
  120. package/runtime/gatewaysdk/environment/schema/openapi_schemas.py +113 -30
  121. package/runtime/gatewaysdk/environment/schema/platform.py +137 -187
  122. package/runtime/gatewaysdk/environment/schema/platform_import.py +2 -3
  123. package/runtime/gatewaysdk/environment/schema/platform_query.py +61 -5
  124. package/runtime/gatewaysdk/environment/schema/primary_key.py +61 -0
  125. package/runtime/gatewaysdk/environment/schema/proof.py +19 -12
  126. package/runtime/gatewaysdk/environment/schema/request_body.py +238 -0
  127. package/runtime/gatewaysdk/environment/schema/request_ledger.py +958 -0
  128. package/runtime/gatewaysdk/environment/schema/route_bindings.py +25 -3
  129. package/runtime/gatewaysdk/environment/schema/route_miss.py +54 -0
  130. package/runtime/gatewaysdk/environment/schema/runtime.py +178 -308
  131. package/runtime/gatewaysdk/environment/schema/served_names.py +58 -0
  132. package/runtime/gatewaysdk/environment/schema/session_files.py +275 -0
  133. package/runtime/gatewaysdk/environment/schema/session_move.py +275 -0
  134. package/runtime/gatewaysdk/environment/schema/skills/agents/connector-template-author.md +5 -1
  135. package/runtime/gatewaysdk/environment/schema/skills/benchmarks-getting-started/SKILL.md +10 -11
  136. package/runtime/gatewaysdk/environment/schema/skills/connector-schema-authoring/SKILL.md +49 -16
  137. package/runtime/gatewaysdk/environment/schema/skills/world-data-ingestion/ROWS.md +39 -9
  138. package/runtime/gatewaysdk/environment/schema/skills/world-data-ingestion/SKILL.md +27 -27
  139. package/runtime/gatewaysdk/environment/schema/skills/worlds-getting-started/SKILL.md +33 -33
  140. package/runtime/gatewaysdk/environment/schema/skills/worlds-getting-started/references/cli-mcp-map.md +13 -7
  141. package/runtime/gatewaysdk/environment/schema/skills/worlds-getting-started/references/gotchas.md +49 -1
  142. package/runtime/gatewaysdk/environment/schema/skills/worlds-getting-started/references/journal-checks.md +182 -0
  143. package/runtime/gatewaysdk/environment/schema/skills/worlds-getting-started/references/openapi-import.md +50 -21
  144. package/runtime/gatewaysdk/environment/schema/slack.py +4 -8
  145. package/runtime/gatewaysdk/environment/schema/snapshot.py +516 -140
  146. package/runtime/gatewaysdk/environment/schema/spill_files.py +228 -0
  147. package/runtime/gatewaysdk/environment/schema/store_contract.py +8 -14
  148. package/runtime/gatewaysdk/environment/schema/tasks.py +267 -276
  149. package/runtime/gatewaysdk/environment/schema/tools_world.py +146 -242
  150. package/runtime/gatewaysdk/environment/schema/ui.py +24 -5
  151. package/runtime/gatewaysdk/environment/schema/ui_static/app.js +100 -130
  152. package/runtime/gatewaysdk/environment/schema/ui_static/index.html +1 -8
  153. package/runtime/gatewaysdk/environment/schema/validation.py +235 -41
  154. package/runtime/gatewaysdk/environment/schema/verbs.py +32 -36
  155. package/runtime/gatewaysdk/environment/schema/worker.py +6 -4
  156. package/runtime/gatewaysdk/environment/schema/workers.py +345 -96
  157. package/runtime/gatewaysdk/environment/schema/world_host.py +953 -0
  158. package/runtime/gatewaysdk/environment/schema/world_sql.py +81 -0
  159. package/runtime/gatewaysdk/environment/schema/world_tests.py +80 -50
  160. package/runtime/gatewaysdk/environment/score.py +57 -0
  161. package/runtime/gatewaysdk/environment/secret_values.py +36 -0
  162. package/runtime/gatewaysdk/environment/world.py +43 -4
  163. package/runtime/gatewaysdk/environment/world_session_contract.py +46 -5
  164. package/skills/agents/connector-template-author.md +5 -1
  165. package/skills/benchmarks-getting-started/SKILL.md +10 -11
  166. package/skills/connector-schema-authoring/SKILL.md +49 -16
  167. package/skills/connector-schema-authoring/connector-worlds.md +142 -11
  168. package/skills/connector-schema-authoring/world-schema.md +103 -51
  169. package/skills/world-data-ingestion/ROWS.md +39 -9
  170. package/skills/world-data-ingestion/SKILL.md +27 -27
  171. package/skills/worlds-getting-started/SKILL.md +33 -33
  172. package/skills/worlds-getting-started/references/cli-mcp-map.md +13 -7
  173. package/skills/worlds-getting-started/references/gotchas.md +49 -1
  174. package/skills/worlds-getting-started/references/journal-checks.md +182 -0
  175. package/skills/worlds-getting-started/references/openapi-import.md +50 -21
  176. package/runtime/gatewaysdk/environment/schema/store.py +0 -1013
@@ -16,6 +16,28 @@ var __esm = (fn, res, err) => function __init() {
16
16
  }
17
17
  };
18
18
 
19
+ // src/worlds/platformEndpoint.ts
20
+ function platformEndpoint(options) {
21
+ const publicKey = options.publicKey ?? process.env.GATEWAY_PUBLIC_KEY;
22
+ const secretKey = options.secretKey ?? process.env.GATEWAY_SECRET_KEY;
23
+ if (!publicKey || !secretKey) return null;
24
+ const host = options.host ?? process.env.GATEWAY_HOST ?? DEFAULT_HOST;
25
+ return { host: host.replace(/\/+$/, ""), publicKey, secretKey };
26
+ }
27
+ function requirePlatformEndpoint(options) {
28
+ const endpoint = platformEndpoint(options);
29
+ if (!endpoint) throw new Error(GATEWAY_KEYS_MISSING);
30
+ return endpoint;
31
+ }
32
+ var DEFAULT_HOST, GATEWAY_KEYS_MISSING;
33
+ var init_platformEndpoint = __esm({
34
+ "src/worlds/platformEndpoint.ts"() {
35
+ "use strict";
36
+ DEFAULT_HOST = "https://withgateway.ai";
37
+ GATEWAY_KEYS_MISSING = "Gateway keys missing: set GATEWAY_PUBLIC_KEY / GATEWAY_SECRET_KEY (or pass publicKey/secretKey).";
38
+ }
39
+ });
40
+
19
41
  // src/worlds/transport.ts
20
42
  function platformTimeoutMs(env = process.env) {
21
43
  const raw = env[PLATFORM_TIMEOUT_ENV];
@@ -24,7 +46,7 @@ function platformTimeoutMs(env = process.env) {
24
46
  if (Number.isInteger(value) && value > 0) return value;
25
47
  throw new Error(`${PLATFORM_TIMEOUT_ENV} must be a positive whole number of milliseconds, not \`${raw}\`.`);
26
48
  }
27
- var PLATFORM_TIMEOUT_ENV, PLATFORM_TIMEOUT_DEFAULT_MS, CHECK_HOST, RETRY, CAUSES, UNKNOWN_CAUSE, TransportCause, UnreachableError, PlatformTransport;
49
+ var PLATFORM_TIMEOUT_ENV, PLATFORM_TIMEOUT_DEFAULT_MS, CHECK_HOST, RETRY, FETCH_LIMIT, CAUSES, UNKNOWN_CAUSE, TransportCause, UnreachableError, sleep, RetryPolicy, Attempt, PlatformTransport;
28
50
  var init_transport = __esm({
29
51
  "src/worlds/transport.ts"() {
30
52
  "use strict";
@@ -32,7 +54,13 @@ var init_transport = __esm({
32
54
  PLATFORM_TIMEOUT_DEFAULT_MS = 12e4;
33
55
  CHECK_HOST = "Check GATEWAY_HOST (or --host) points at a running platform, then retry.";
34
56
  RETRY = "Retry; if it repeats, check the network between here and the platform.";
57
+ FETCH_LIMIT = {
58
+ reason: "Node's fetch stopped waiting after 300 s",
59
+ next: "The platform may still be running it: check what it changed before you retry."
60
+ };
35
61
  CAUSES = {
62
+ UND_ERR_HEADERS_TIMEOUT: FETCH_LIMIT,
63
+ UND_ERR_BODY_TIMEOUT: FETCH_LIMIT,
36
64
  ECONNREFUSED: { reason: "connection refused", next: CHECK_HOST },
37
65
  ENOTFOUND: { reason: "DNS lookup failed", next: CHECK_HOST },
38
66
  EAI_AGAIN: { reason: "DNS lookup failed", next: CHECK_HOST },
@@ -86,6 +114,56 @@ var init_transport = __esm({
86
114
  route;
87
115
  failure;
88
116
  };
117
+ sleep = (ms) => new Promise((resolve4) => setTimeout(resolve4, ms));
118
+ RetryPolicy = class _RetryPolicy {
119
+ constructor(delaysMs, wait = sleep, budgetMs = Number.POSITIVE_INFINITY, now = Date.now) {
120
+ this.delaysMs = delaysMs;
121
+ this.wait = wait;
122
+ this.budgetMs = budgetMs;
123
+ this.now = now;
124
+ }
125
+ delaysMs;
126
+ wait;
127
+ budgetMs;
128
+ now;
129
+ static NONE = new _RetryPolicy([]);
130
+ /** A platform restart or a short edge outage: no wait starts that would end past five minutes, so a step ends
131
+ * within the budget plus one request timeout. */
132
+ static FILING = new _RetryPolicy([250, 500, 1e3, 2e3, 4e3, 8e3, 16e3, 3e4], sleep, 3e5);
133
+ static TRANSIENT_STATUSES = /* @__PURE__ */ new Set([502, 503, 504]);
134
+ async run(attempt) {
135
+ const started = this.now();
136
+ for (let tries = 0; ; tries += 1) {
137
+ const outcome = await Attempt.of(attempt);
138
+ const delayMs = this.delaysMs[tries];
139
+ const spent = delayMs === void 0 || this.now() - started + delayMs >= this.budgetMs;
140
+ if (!outcome.transient || spent) return outcome.settle();
141
+ await this.wait(delayMs);
142
+ }
143
+ }
144
+ };
145
+ Attempt = class _Attempt {
146
+ constructor(reply, error, transient) {
147
+ this.reply = reply;
148
+ this.error = error;
149
+ this.transient = transient;
150
+ }
151
+ reply;
152
+ error;
153
+ transient;
154
+ static async of(attempt) {
155
+ try {
156
+ const reply = await attempt();
157
+ return new _Attempt(reply, null, RetryPolicy.TRANSIENT_STATUSES.has(reply.status));
158
+ } catch (error) {
159
+ return new _Attempt(null, error, error instanceof UnreachableError);
160
+ }
161
+ }
162
+ settle() {
163
+ if (this.reply) return this.reply;
164
+ throw this.error;
165
+ }
166
+ };
89
167
  PlatformTransport = class {
90
168
  constructor(endpoint, timeoutMs = platformTimeoutMs()) {
91
169
  this.endpoint = endpoint;
@@ -99,6 +177,9 @@ var init_transport = __esm({
99
177
  }
100
178
  async send(method, route, body, opts = {}) {
101
179
  const timeoutMs = this.budget(opts.timeoutMs);
180
+ return (opts.retry ?? RetryPolicy.NONE).run(() => this.once(method, route, body, timeoutMs));
181
+ }
182
+ async once(method, route, body, timeoutMs) {
102
183
  const payload = body === void 0 ? {} : { body: JSON.stringify(body) };
103
184
  const controller = new AbortController();
104
185
  const timer = setTimeout(() => controller.abort(), timeoutMs);
@@ -471,13 +552,13 @@ var init_screen = __esm({
471
552
  });
472
553
  }
473
554
  async drag(action) {
474
- const path8 = action.args.path ?? [];
475
- if (path8.length < 2) throw new Error("a drag needs at least two points");
555
+ const path9 = action.args.path ?? [];
556
+ if (path9.length < 2) throw new Error("a drag needs at least two points");
476
557
  return this.held(action.args.modifiers ?? [], async () => {
477
- await this.moveTo(path8[0]);
558
+ await this.moveTo(path9[0]);
478
559
  await this.page.mouse.down({ button: "left" });
479
560
  try {
480
- for (const point2 of path8.slice(1)) await this.moveTo(point2, DRAG_STEPS);
561
+ for (const point2 of path9.slice(1)) await this.moveTo(point2, DRAG_STEPS);
481
562
  } finally {
482
563
  await this.page.mouse.up({ button: "left" });
483
564
  }
@@ -568,7 +649,7 @@ var init_media = __esm({
568
649
  put;
569
650
  maxBytes;
570
651
  /** The uploader for `GATEWAY_HOST` / `GATEWAY_PUBLIC_KEY` /
571
- * `GATEWAY_SECRET_KEY` (the keys tracing exports with); null when any is unset. */
652
+ * `GATEWAY_SECRET_KEY` only; null when any is unset, so a run traced with a saved login uploads none. */
572
653
  static fromEnv(env = process.env) {
573
654
  const host = env.GATEWAY_HOST;
574
655
  const publicKey = env.GATEWAY_PUBLIC_KEY;
@@ -1425,17 +1506,43 @@ var init_nativeComputer = __esm({
1425
1506
  });
1426
1507
 
1427
1508
  // src/worlds/sessionContract.ts
1428
- var CALL_BODY_LIMIT_BYTES, EXPLORATORY_TASK;
1509
+ var CALL_BODY_LIMIT_BYTES, REQUEST_BODY_CAPTURE_BYTES, EXPLORATORY_TASK;
1429
1510
  var init_sessionContract = __esm({
1430
1511
  "src/worlds/sessionContract.ts"() {
1431
1512
  "use strict";
1432
1513
  CALL_BODY_LIMIT_BYTES = 4 * 1024 * 1024;
1514
+ REQUEST_BODY_CAPTURE_BYTES = 64 * 1024;
1433
1515
  EXPLORATORY_TASK = Object.freeze({
1434
1516
  instruction: "exploratory session"
1435
1517
  });
1436
1518
  }
1437
1519
  });
1438
1520
 
1521
+ // src/worlds/toolSchema.ts
1522
+ var init_toolSchema = __esm({
1523
+ "src/worlds/toolSchema.ts"() {
1524
+ "use strict";
1525
+ }
1526
+ });
1527
+
1528
+ // src/worlds/requestLedger.ts
1529
+ var init_requestLedger = __esm({
1530
+ "src/worlds/requestLedger.ts"() {
1531
+ "use strict";
1532
+ init_worlds();
1533
+ init_sessionContract();
1534
+ }
1535
+ });
1536
+
1537
+ // src/worlds/sessionReadiness.ts
1538
+ var READY_TIMEOUT_MS;
1539
+ var init_sessionReadiness = __esm({
1540
+ "src/worlds/sessionReadiness.ts"() {
1541
+ "use strict";
1542
+ READY_TIMEOUT_MS = 10 * 6e4;
1543
+ }
1544
+ });
1545
+
1439
1546
  // src/tracing/session.ts
1440
1547
  import { AsyncLocalStorage } from "async_hooks";
1441
1548
  var processStorage, currentSessionStorage, currentWorldSessionStorage;
@@ -1460,9 +1567,23 @@ var init_taskRef = __esm({
1460
1567
  }
1461
1568
  });
1462
1569
 
1570
+ // src/worlds/worldNotice.ts
1571
+ var init_worldNotice = __esm({
1572
+ "src/worlds/worldNotice.ts"() {
1573
+ "use strict";
1574
+ }
1575
+ });
1576
+
1577
+ // src/worlds/grade.ts
1578
+ var init_grade = __esm({
1579
+ "src/worlds/grade.ts"() {
1580
+ "use strict";
1581
+ }
1582
+ });
1583
+
1463
1584
  // src/worlds/session.ts
1464
1585
  import { randomUUID } from "crypto";
1465
- var READY_TIMEOUT_MS, CALL_TIMEOUT_MS, JUDGED_GRADE_TIMEOUT_MS;
1586
+ var CALL_TIMEOUT_MS, JUDGED_GRADE_TIMEOUT_MS;
1466
1587
  var init_session2 = __esm({
1467
1588
  "src/worlds/session.ts"() {
1468
1589
  "use strict";
@@ -1470,10 +1591,15 @@ var init_session2 = __esm({
1470
1591
  init_browser();
1471
1592
  init_nativeComputer();
1472
1593
  init_sessionContract();
1594
+ init_toolSchema();
1595
+ init_requestLedger();
1596
+ init_sessionReadiness();
1473
1597
  init_session();
1474
1598
  init_taskRef();
1599
+ init_worldNotice();
1600
+ init_grade();
1475
1601
  init_taskRef();
1476
- READY_TIMEOUT_MS = 10 * 6e4;
1602
+ init_sessionReadiness();
1477
1603
  CALL_TIMEOUT_MS = 3 * 6e4;
1478
1604
  JUDGED_GRADE_TIMEOUT_MS = 15 * 6e4;
1479
1605
  }
@@ -1495,6 +1621,14 @@ var init_tasks = __esm({
1495
1621
  }
1496
1622
  });
1497
1623
 
1624
+ // src/worlds/taskGrades.ts
1625
+ var init_taskGrades = __esm({
1626
+ "src/worlds/taskGrades.ts"() {
1627
+ "use strict";
1628
+ init_worlds();
1629
+ }
1630
+ });
1631
+
1498
1632
  // src/worlds/surfaceDescriptor.ts
1499
1633
  var init_surfaceDescriptor = __esm({
1500
1634
  "src/worlds/surfaceDescriptor.ts"() {
@@ -1509,6 +1643,7 @@ var init_taskSessions = __esm({
1509
1643
  "use strict";
1510
1644
  init_worlds();
1511
1645
  init_browser();
1646
+ init_grade();
1512
1647
  init_surfaceDescriptor();
1513
1648
  init_session2();
1514
1649
  }
@@ -1519,13 +1654,50 @@ var init_evals = __esm({
1519
1654
  "src/worlds/evals.ts"() {
1520
1655
  "use strict";
1521
1656
  init_worlds();
1657
+ init_transport();
1658
+ }
1659
+ });
1660
+
1661
+ // src/worlds/runSignals.ts
1662
+ import { constants } from "os";
1663
+ var init_runSignals = __esm({
1664
+ "src/worlds/runSignals.ts"() {
1665
+ "use strict";
1666
+ }
1667
+ });
1668
+
1669
+ // src/worlds/taskRunDir.ts
1670
+ import * as fs from "fs";
1671
+ import * as path from "path";
1672
+ var init_taskRunDir = __esm({
1673
+ "src/worlds/taskRunDir.ts"() {
1674
+ "use strict";
1675
+ init_browser();
1676
+ }
1677
+ });
1678
+
1679
+ // src/worlds/taskRunOutcome.ts
1680
+ var init_taskRunOutcome = __esm({
1681
+ "src/worlds/taskRunOutcome.ts"() {
1682
+ "use strict";
1683
+ init_grade();
1684
+ init_taskSessions();
1522
1685
  }
1523
1686
  });
1524
1687
 
1525
1688
  // src/tracing/prerequisites.ts
1689
+ var OPENTELEMETRY_PEERS, PINNED_PEERS;
1526
1690
  var init_prerequisites = __esm({
1527
1691
  "src/tracing/prerequisites.ts"() {
1528
1692
  "use strict";
1693
+ OPENTELEMETRY_PEERS = {
1694
+ "@opentelemetry/api": "1.9.0",
1695
+ "@opentelemetry/exporter-trace-otlp-http": "0.222.0",
1696
+ "@opentelemetry/resources": "2.11.0",
1697
+ "@opentelemetry/sdk-trace-base": "2.11.0",
1698
+ "@opentelemetry/sdk-trace-node": "2.11.0"
1699
+ };
1700
+ PINNED_PEERS = Object.entries(OPENTELEMETRY_PEERS).map(([name, version]) => `${name}@${version}`).join(" ");
1529
1701
  }
1530
1702
  });
1531
1703
 
@@ -1534,21 +1706,25 @@ var init_taskTracing = __esm({
1534
1706
  "src/worlds/taskTracing.ts"() {
1535
1707
  "use strict";
1536
1708
  init_prerequisites();
1709
+ init_platformEndpoint();
1537
1710
  }
1538
1711
  });
1539
1712
 
1540
1713
  // src/worlds/taskRun.ts
1541
1714
  import { randomBytes } from "crypto";
1542
- import * as fs from "fs";
1543
- import * as path from "path";
1715
+ import * as path2 from "path";
1544
1716
  var init_taskRun = __esm({
1545
1717
  "src/worlds/taskRun.ts"() {
1546
1718
  "use strict";
1547
1719
  init_browser();
1548
1720
  init_evals();
1721
+ init_runSignals();
1549
1722
  init_session2();
1550
1723
  init_taskSessions();
1724
+ init_taskRunDir();
1725
+ init_taskRunOutcome();
1551
1726
  init_taskTracing();
1727
+ init_worldNotice();
1552
1728
  }
1553
1729
  });
1554
1730
 
@@ -1566,6 +1742,7 @@ var init_setRun = __esm({
1566
1742
  "use strict";
1567
1743
  init_worlds();
1568
1744
  init_checkoutProvenance();
1745
+ init_runSignals();
1569
1746
  init_taskRun();
1570
1747
  }
1571
1748
  });
@@ -1574,12 +1751,13 @@ var init_setRun = __esm({
1574
1751
  var init_requestLog = __esm({
1575
1752
  "src/worlds/requestLog.ts"() {
1576
1753
  "use strict";
1754
+ init_requestLedger();
1577
1755
  }
1578
1756
  });
1579
1757
 
1580
1758
  // src/worlds/checkoutTarget.ts
1581
1759
  import * as fs2 from "fs";
1582
- import * as path2 from "path";
1760
+ import * as path3 from "path";
1583
1761
  var init_checkoutTarget = __esm({
1584
1762
  "src/worlds/checkoutTarget.ts"() {
1585
1763
  "use strict";
@@ -1589,7 +1767,7 @@ var init_checkoutTarget = __esm({
1589
1767
  // src/worlds/worldDir.ts
1590
1768
  import { createHash as createHash2 } from "crypto";
1591
1769
  import * as fs3 from "fs";
1592
- import * as path3 from "path";
1770
+ import * as path4 from "path";
1593
1771
  var CONNECTOR_SPEC, WORLD_SCHEMA_MARKERS, WORLD_ROOT_MARKERS;
1594
1772
  var init_worldDir = __esm({
1595
1773
  "src/worlds/worldDir.ts"() {
@@ -1602,7 +1780,7 @@ var init_worldDir = __esm({
1602
1780
 
1603
1781
  // src/worlds/tar.ts
1604
1782
  import * as fs4 from "fs";
1605
- import * as path4 from "path";
1783
+ import * as path5 from "path";
1606
1784
  import { gunzipSync } from "zlib";
1607
1785
  var init_tar = __esm({
1608
1786
  "src/worlds/tar.ts"() {
@@ -1614,7 +1792,7 @@ var init_tar = __esm({
1614
1792
  import { createHash as createHash3 } from "crypto";
1615
1793
  import { gzipSync } from "zlib";
1616
1794
  import * as fs5 from "fs";
1617
- import * as path5 from "path";
1795
+ import * as path6 from "path";
1618
1796
  var META_RELPATH;
1619
1797
  var init_hub = __esm({
1620
1798
  "src/worlds/hub.ts"() {
@@ -1623,7 +1801,7 @@ var init_hub = __esm({
1623
1801
  init_checkoutTarget();
1624
1802
  init_worldDir();
1625
1803
  init_tar();
1626
- META_RELPATH = path5.join(".gateway", ".env-metadata.json");
1804
+ META_RELPATH = path6.join(".gateway", ".env-metadata.json");
1627
1805
  }
1628
1806
  });
1629
1807
 
@@ -1637,10 +1815,14 @@ var init_validate = __esm({
1637
1815
  });
1638
1816
 
1639
1817
  // src/worlds/sandbox.ts
1818
+ import { createHash as createHash4, randomUUID as randomUUID2 } from "crypto";
1819
+ var SANDBOX_WRITE_CHUNK_BYTES, SANDBOX_FILE_MAX_BYTES;
1640
1820
  var init_sandbox = __esm({
1641
1821
  "src/worlds/sandbox.ts"() {
1642
1822
  "use strict";
1643
1823
  init_worlds();
1824
+ SANDBOX_WRITE_CHUNK_BYTES = 4 * 1024 * 1024;
1825
+ SANDBOX_FILE_MAX_BYTES = 256 * 1024 * 1024;
1644
1826
  }
1645
1827
  });
1646
1828
 
@@ -1661,7 +1843,7 @@ var init_json = __esm({
1661
1843
  });
1662
1844
 
1663
1845
  // src/worlds/transforms.ts
1664
- import { createHash as createHash4 } from "crypto";
1846
+ import { createHash as createHash5 } from "crypto";
1665
1847
  var WHITESPACE, WHITESPACE_EDGES, WHITESPACE_RUN, NOT_DIGIT, STRIP_PREFIX, trim, emailLocalPart, emailDomain, hex, SIMPLE, TRANSFORMS;
1666
1848
  var init_transforms = __esm({
1667
1849
  "src/worlds/transforms.ts"() {
@@ -1681,7 +1863,7 @@ var init_transforms = __esm({
1681
1863
  const at = value.lastIndexOf("@");
1682
1864
  return at === -1 ? "" : value.slice(at + 1).toLowerCase();
1683
1865
  };
1684
- hex = (algorithm, value) => createHash4(algorithm).update(value, "utf8").digest("hex");
1866
+ hex = (algorithm, value) => createHash5(algorithm).update(value, "utf8").digest("hex");
1685
1867
  SIMPLE = {
1686
1868
  lower: (value) => value.toLowerCase(),
1687
1869
  upper: (value) => value.toUpperCase(),
@@ -1701,7 +1883,7 @@ var init_transforms = __esm({
1701
1883
  });
1702
1884
 
1703
1885
  // src/worlds/redaction.ts
1704
- import { createHash as createHash5 } from "crypto";
1886
+ import { createHash as createHash6 } from "crypto";
1705
1887
  var init_redaction = __esm({
1706
1888
  "src/worlds/redaction.ts"() {
1707
1889
  "use strict";
@@ -1729,11 +1911,12 @@ var init_migrate = __esm({
1729
1911
  // src/worlds/ingest.ts
1730
1912
  import * as fs6 from "fs";
1731
1913
  import * as os from "os";
1732
- import * as path6 from "path";
1914
+ import * as path7 from "path";
1733
1915
  var init_ingest = __esm({
1734
1916
  "src/worlds/ingest.ts"() {
1735
1917
  "use strict";
1736
1918
  init_worlds();
1919
+ init_platformEndpoint();
1737
1920
  }
1738
1921
  });
1739
1922
 
@@ -1754,52 +1937,58 @@ var init_dryRun = __esm({
1754
1937
  });
1755
1938
 
1756
1939
  // src/worlds/index.ts
1757
- function resolveEnv(options) {
1758
- const host = options.host ?? process.env.GATEWAY_HOST ?? "https://withgateway.ai";
1759
- const publicKey = options.publicKey ?? process.env.GATEWAY_PUBLIC_KEY;
1760
- const secretKey = options.secretKey ?? process.env.GATEWAY_SECRET_KEY;
1761
- if (!publicKey || !secretKey) {
1762
- throw new Error(
1763
- "Gateway keys missing: set GATEWAY_PUBLIC_KEY / GATEWAY_SECRET_KEY (or pass publicKey/secretKey)."
1764
- );
1765
- }
1766
- return { host: host.replace(/\/+$/, ""), publicKey, secretKey };
1940
+ function edgeAnswer(text, status) {
1941
+ if (status !== void 0 && status >= 500) return EDGE_ANSWERS[status] ?? EDGE_FAILURE;
1942
+ return /^\s*</.test(text) ? EDGE_PAGE : null;
1767
1943
  }
1768
- function parseErrorBody(text, limit = 600) {
1769
- const raw = { detail: text.slice(0, limit), code: null };
1944
+ function parseErrorBody(text, status) {
1945
+ const raw = { detail: text.slice(0, DETAIL_LIMIT), code: null };
1770
1946
  let parsed;
1771
1947
  try {
1772
1948
  parsed = JSON.parse(text);
1773
1949
  } catch {
1774
- return raw;
1950
+ return { detail: (edgeAnswer(text, status) ?? text).slice(0, DETAIL_LIMIT), code: null };
1775
1951
  }
1776
1952
  if (parsed === null || typeof parsed !== "object") return raw;
1777
- const { message, code } = parsed;
1953
+ const { message, code, error } = parsed;
1778
1954
  const stableCode = typeof code === "string" ? code : null;
1779
1955
  if (typeof message !== "string") return { ...raw, code: stableCode };
1780
- if (stableCode === null)
1781
- return { detail: message.slice(0, limit), code: null };
1956
+ const fields = invalidFields(error);
1957
+ const said = fields ? `${message}: ${fields}` : message;
1958
+ if (stableCode === null) return { detail: said.slice(0, DETAIL_LIMIT), code: null };
1782
1959
  return {
1783
- detail: `${message} (${stableCode})`.slice(0, limit),
1960
+ detail: `${said} (${stableCode})`.slice(0, DETAIL_LIMIT),
1784
1961
  code: stableCode
1785
1962
  };
1786
1963
  }
1787
- async function apiRequest(options, method, path8, body, init = {}) {
1788
- const reply = await new PlatformTransport(resolveEnv(options)).send(method, path8, body, init);
1789
- if (!reply.ok) throw new ApiError(reply.status, method, path8, reply.text);
1964
+ function invalidFields(error) {
1965
+ const issues = Array.isArray(error) ? error : [];
1966
+ return issues.filter(
1967
+ (issue) => issue !== null && typeof issue === "object" && typeof issue.message === "string"
1968
+ ).map((issue) => {
1969
+ const path9 = Array.isArray(issue.path) ? issue.path.map(String).join(".") : "";
1970
+ return path9 ? `${path9}: ${issue.message}` : issue.message;
1971
+ }).join("; ");
1972
+ }
1973
+ async function apiRequest(options, method, path9, body, init = {}) {
1974
+ const reply = await new PlatformTransport(requirePlatformEndpoint(options)).send(method, path9, body, init);
1975
+ if (!reply.ok) throw new ApiError(reply.status, method, path9, reply.text);
1790
1976
  return JSON.parse(reply.text);
1791
1977
  }
1792
- var ApiError;
1978
+ var ApiError, DETAIL_LIMIT, EDGE_ANSWERS, EDGE_FAILURE, EDGE_PAGE;
1793
1979
  var init_worlds = __esm({
1794
1980
  "src/worlds/index.ts"() {
1795
1981
  "use strict";
1982
+ init_platformEndpoint();
1796
1983
  init_transport();
1797
1984
  init_transport();
1798
1985
  init_session2();
1986
+ init_grade();
1799
1987
  init_sessionList();
1800
1988
  init_sessionContract();
1801
1989
  init_taskRef();
1802
1990
  init_tasks();
1991
+ init_taskGrades();
1803
1992
  init_taskSessions();
1804
1993
  init_taskRun();
1805
1994
  init_setRun();
@@ -1808,6 +1997,7 @@ var init_worlds = __esm({
1808
1997
  init_browser();
1809
1998
  init_surfaceDescriptor();
1810
1999
  init_requestLog();
2000
+ init_requestLedger();
1811
2001
  init_browserReconnect();
1812
2002
  init_nativeComputer();
1813
2003
  init_hub();
@@ -1821,10 +2011,11 @@ var init_worlds = __esm({
1821
2011
  init_sandbox();
1822
2012
  init_editSessions();
1823
2013
  init_dryRun();
2014
+ init_worldNotice();
1824
2015
  ApiError = class extends Error {
1825
- constructor(status, method, path8, text) {
1826
- const parsed = parseErrorBody(text);
1827
- super(`${method} ${path8} -> ${status}: ${parsed.detail}`);
2016
+ constructor(status, method, path9, text) {
2017
+ const parsed = parseErrorBody(text, status);
2018
+ super(`${method} ${path9} -> ${status}: ${parsed.detail}`);
1828
2019
  this.status = status;
1829
2020
  this.text = text;
1830
2021
  this.name = "ApiError";
@@ -1834,14 +2025,22 @@ var init_worlds = __esm({
1834
2025
  text;
1835
2026
  code;
1836
2027
  };
2028
+ DETAIL_LIMIT = 600;
2029
+ EDGE_ANSWERS = {
2030
+ 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.",
2031
+ 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.",
2032
+ 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."
2033
+ };
2034
+ 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.";
2035
+ 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.";
1837
2036
  }
1838
2037
  });
1839
2038
 
1840
2039
  // src/files/index.ts
1841
2040
  init_worlds();
1842
- import { createHash as createHash6 } from "crypto";
2041
+ import { createHash as createHash7 } from "crypto";
1843
2042
  import * as fs7 from "fs";
1844
- import * as path7 from "path";
2043
+ import * as path8 from "path";
1845
2044
  import { Readable, Transform } from "stream";
1846
2045
  import { pipeline } from "stream/promises";
1847
2046
  var DRIVE_PREFIX = "drive:";
@@ -1892,7 +2091,7 @@ async function readFile(options = {}, filePath, limits = {}) {
1892
2091
  async function downloadFile(options = {}, filePath, outPath, onProgress) {
1893
2092
  const file = await getFile(options, filePath);
1894
2093
  const res = await openDownload(file.url);
1895
- fs7.mkdirSync(path7.dirname(path7.resolve(outPath)), { recursive: true });
2094
+ fs7.mkdirSync(path8.dirname(path8.resolve(outPath)), { recursive: true });
1896
2095
  const source = Readable.fromWeb(res.body);
1897
2096
  await pipeline(source, counting((n) => onProgress?.(n, file.sizeBytes)), fs7.createWriteStream(outPath));
1898
2097
  return { ...file, out: outPath };
@@ -1904,7 +2103,7 @@ async function confirmUpload(options = {}, fileId, ok = true) {
1904
2103
  return apiRequest(options, "POST", `${BASE}/confirm`, { fileId, ok });
1905
2104
  }
1906
2105
  async function sha256Base64(localPath) {
1907
- const hash = createHash6("sha256");
2106
+ const hash = createHash7("sha256");
1908
2107
  for await (const chunk of fs7.createReadStream(localPath)) hash.update(chunk);
1909
2108
  return hash.digest("base64");
1910
2109
  }
@@ -1941,7 +2140,7 @@ var CONTENT_TYPES = {
1941
2140
  ".mp4": "video/mp4"
1942
2141
  };
1943
2142
  function contentTypeFor(name) {
1944
- return CONTENT_TYPES[path7.extname(name).toLowerCase()] ?? "application/octet-stream";
2143
+ return CONTENT_TYPES[path8.extname(name).toLowerCase()] ?? "application/octet-stream";
1945
2144
  }
1946
2145
  function counting(report) {
1947
2146
  let seen = 0;
@@ -1989,7 +2188,7 @@ async function uploadBytes(options = {}, bytes, targetPath, upload = {}) {
1989
2188
  if (!bytes.length) throw new Error("nothing to upload: the content is empty");
1990
2189
  const target = drivePath(targetPath);
1991
2190
  const contentType = upload.contentType ?? contentTypeFor(target);
1992
- const sha256 = createHash6("sha256").update(bytes).digest("base64");
2191
+ const sha256 = createHash7("sha256").update(bytes).digest("base64");
1993
2192
  const granted = await requestUpload(options, { path: target, contentLength: bytes.length, contentType, sha256, ...upload.overwrite ? { overwrite: true } : {} });
1994
2193
  try {
1995
2194
  await putPresigned(granted.uploadUrl, new Uint8Array(bytes), { contentType, contentLength: bytes.length, sha256 });