@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
@@ -1,5 +1,5 @@
1
- export { I as IdentifyOptions, a as IdentitySpanProcessor, O as ObservationKind, b as ObserveClaudeOptions, c as ObserveOptions, S as SECRET_KEYS, d as SESSION_ID_ATTRIBUTE, e as SecretRedactingSpanProcessor, f as SessionSpanProcessor, g as SpanSecrets, T as TracingConfig, h as TracingHandle, j as TracingState, U as USER_ID_ATTRIBUTE, W as WORLD_SESSION_ID_ATTRIBUTE, k as flush, l as getAmbientSessionId, m as getCurrentWorldSessionId, i as identify, n as init, o as initIsolated, p as isGatewayConfigured, q as isInitialized, s as observe, t as observeAnthropic, u as observeClaude, v as observeOpenAI, w as resetAmbientUser, r as resolveUserId, x as shutdown, y as withSession, z as withWorldSession } from '../index-D-AMnAMa.mjs';
2
- export { M as MAX_MEDIA_BYTES, f as MediaField, g as MediaReference, h as MediaUploadError, i as MediaUploader } from '../media-CbcAfQvd.mjs';
1
+ export { I as IdentifyOptions, a as IdentitySpanProcessor, O as ObservationKind, b as ObserveClaudeOptions, c as ObserveOptions, S as SECRET_KEYS, d as SESSION_ID_ATTRIBUTE, e as SecretRedactingSpanProcessor, f as SessionSpanProcessor, g as SpanSecrets, T as TracingConfig, h as TracingHandle, j as TracingState, U as USER_ID_ATTRIBUTE, W as WORLD_SESSION_ID_ATTRIBUTE, k as flush, l as getAmbientSessionId, m as getCurrentWorldSessionId, i as identify, n as init, o as initIsolated, p as isGatewayConfigured, q as isInitialized, s as observe, t as observeAnthropic, u as observeClaude, v as observeOpenAI, w as resetAmbientUser, r as resolveUserId, x as shutdown, y as withSession, z as withWorldSession } from '../index-mJhG3vZU.mjs';
2
+ export { M as MAX_MEDIA_BYTES, f as MediaField, g as MediaReference, h as MediaUploadError, i as MediaUploader } from '../media-BIApiPzS.mjs';
3
3
  import '@opentelemetry/api';
4
4
  import '../scores/index.mjs';
5
5
  import '@opentelemetry/sdk-trace-base';
@@ -1,5 +1,5 @@
1
- export { I as IdentifyOptions, a as IdentitySpanProcessor, O as ObservationKind, b as ObserveClaudeOptions, c as ObserveOptions, S as SECRET_KEYS, d as SESSION_ID_ATTRIBUTE, e as SecretRedactingSpanProcessor, f as SessionSpanProcessor, g as SpanSecrets, T as TracingConfig, h as TracingHandle, j as TracingState, U as USER_ID_ATTRIBUTE, W as WORLD_SESSION_ID_ATTRIBUTE, k as flush, l as getAmbientSessionId, m as getCurrentWorldSessionId, i as identify, n as init, o as initIsolated, p as isGatewayConfigured, q as isInitialized, s as observe, t as observeAnthropic, u as observeClaude, v as observeOpenAI, w as resetAmbientUser, r as resolveUserId, x as shutdown, y as withSession, z as withWorldSession } from '../index-CBqbB_0J.js';
2
- export { M as MAX_MEDIA_BYTES, f as MediaField, g as MediaReference, h as MediaUploadError, i as MediaUploader } from '../media-CbcAfQvd.js';
1
+ export { I as IdentifyOptions, a as IdentitySpanProcessor, O as ObservationKind, b as ObserveClaudeOptions, c as ObserveOptions, S as SECRET_KEYS, d as SESSION_ID_ATTRIBUTE, e as SecretRedactingSpanProcessor, f as SessionSpanProcessor, g as SpanSecrets, T as TracingConfig, h as TracingHandle, j as TracingState, U as USER_ID_ATTRIBUTE, W as WORLD_SESSION_ID_ATTRIBUTE, k as flush, l as getAmbientSessionId, m as getCurrentWorldSessionId, i as identify, n as init, o as initIsolated, p as isGatewayConfigured, q as isInitialized, s as observe, t as observeAnthropic, u as observeClaude, v as observeOpenAI, w as resetAmbientUser, r as resolveUserId, x as shutdown, y as withSession, z as withWorldSession } from '../index-DUHmS74p.js';
2
+ export { M as MAX_MEDIA_BYTES, f as MediaField, g as MediaReference, h as MediaUploadError, i as MediaUploader } from '../media-BIApiPzS.js';
3
3
  import '@opentelemetry/api';
4
4
  import '../scores/index.js';
5
5
  import '@opentelemetry/sdk-trace-base';
@@ -29,7 +29,7 @@ var require_package = __commonJS({
29
29
  "package.json"(exports2, module2) {
30
30
  module2.exports = {
31
31
  name: "@withgateway/sdk",
32
- version: "0.3.1",
32
+ version: "0.4.0",
33
33
  description: "Gateway SDK for TypeScript - A/B experiments, tracing, and observability",
34
34
  main: "./dist/index.js",
35
35
  module: "./dist/index.mjs",
@@ -1209,15 +1209,18 @@ var GATEWAY_ENV = {
1209
1209
  HOST: "GATEWAY_HOST",
1210
1210
  PUBLIC_KEY: "GATEWAY_PUBLIC_KEY",
1211
1211
  SECRET_KEY: "GATEWAY_SECRET_KEY",
1212
+ API_KEY: "GATEWAY_API_KEY",
1212
1213
  ENDPOINT: "GATEWAY_OTLP_ENDPOINT"
1213
1214
  };
1214
- var OPENTELEMETRY_PEERS = [
1215
- "@opentelemetry/api",
1216
- "@opentelemetry/exporter-trace-otlp-http",
1217
- "@opentelemetry/resources",
1218
- "@opentelemetry/sdk-trace-base",
1219
- "@opentelemetry/sdk-trace-node"
1220
- ];
1215
+ var OTLP_TRACES_PATH = "/api/public/otel/v1/traces";
1216
+ var OPENTELEMETRY_PEERS = {
1217
+ "@opentelemetry/api": "1.9.0",
1218
+ "@opentelemetry/exporter-trace-otlp-http": "0.222.0",
1219
+ "@opentelemetry/resources": "2.11.0",
1220
+ "@opentelemetry/sdk-trace-base": "2.11.0",
1221
+ "@opentelemetry/sdk-trace-node": "2.11.0"
1222
+ };
1223
+ var PINNED_PEERS = Object.entries(OPENTELEMETRY_PEERS).map(([name, version]) => `${name}@${version}`).join(" ");
1221
1224
  var MODULE_NOT_FOUND = /* @__PURE__ */ new Set(["MODULE_NOT_FOUND", "ERR_MODULE_NOT_FOUND"]);
1222
1225
  function getEnv(key) {
1223
1226
  const value = process.env[key];
@@ -1229,8 +1232,9 @@ function isGatewayConfigured() {
1229
1232
  var OpenTelemetryMissing = class _OpenTelemetryMissing extends Error {
1230
1233
  constructor() {
1231
1234
  super(
1232
- `OpenTelemetry packages not found. Install them with:
1233
- npm install ${OPENTELEMETRY_PEERS.join(" ")}`
1235
+ `OpenTelemetry packages not found. Install them next to @withgateway/sdk, at the versions it is tested with:
1236
+ npm install ${PINNED_PEERS}
1237
+ npm install -g ${PINNED_PEERS} (the gateway CLI, when it was installed with npm install -g)`
1234
1238
  );
1235
1239
  this.name = "OpenTelemetryMissing";
1236
1240
  }
@@ -1242,7 +1246,6 @@ npm install ${OPENTELEMETRY_PEERS.join(" ")}`
1242
1246
  };
1243
1247
 
1244
1248
  // src/tracing/init.ts
1245
- var DEFAULT_OTLP_PATH = "/api/public/otel/v1/traces";
1246
1249
  var state = {
1247
1250
  initialized: false,
1248
1251
  provider: null
@@ -1259,7 +1262,7 @@ function buildProvider(config, logFn) {
1259
1262
  const host = config.host ?? getEnv(GATEWAY_ENV.HOST);
1260
1263
  const publicKey = config.publicKey ?? getEnv(GATEWAY_ENV.PUBLIC_KEY);
1261
1264
  const secretKey = config.secretKey ?? getEnv(GATEWAY_ENV.SECRET_KEY);
1262
- const endpoint = config.endpoint ?? getEnv(GATEWAY_ENV.ENDPOINT) ?? (host ? `${host.replace(/\/$/, "")}${DEFAULT_OTLP_PATH}` : void 0);
1265
+ const endpoint = config.endpoint ?? getEnv(GATEWAY_ENV.ENDPOINT) ?? (host ? `${host.replace(/\/$/, "")}${OTLP_TRACES_PATH}` : void 0);
1263
1266
  const missing = [];
1264
1267
  if (!host) missing.push("host (or GATEWAY_HOST env var)");
1265
1268
  if (!publicKey) missing.push("publicKey (or GATEWAY_PUBLIC_KEY env var)");
@@ -1775,7 +1778,13 @@ function platformTimeoutMs(env = process.env) {
1775
1778
  }
1776
1779
  var CHECK_HOST = "Check GATEWAY_HOST (or --host) points at a running platform, then retry.";
1777
1780
  var RETRY = "Retry; if it repeats, check the network between here and the platform.";
1781
+ var FETCH_LIMIT = {
1782
+ reason: "Node's fetch stopped waiting after 300 s",
1783
+ next: "The platform may still be running it: check what it changed before you retry."
1784
+ };
1778
1785
  var CAUSES = {
1786
+ UND_ERR_HEADERS_TIMEOUT: FETCH_LIMIT,
1787
+ UND_ERR_BODY_TIMEOUT: FETCH_LIMIT,
1779
1788
  ECONNREFUSED: { reason: "connection refused", next: CHECK_HOST },
1780
1789
  ENOTFOUND: { reason: "DNS lookup failed", next: CHECK_HOST },
1781
1790
  EAI_AGAIN: { reason: "DNS lookup failed", next: CHECK_HOST },
@@ -1829,6 +1838,56 @@ var UnreachableError = class extends Error {
1829
1838
  route;
1830
1839
  failure;
1831
1840
  };
1841
+ var sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
1842
+ var RetryPolicy = class _RetryPolicy {
1843
+ constructor(delaysMs, wait = sleep, budgetMs = Number.POSITIVE_INFINITY, now = Date.now) {
1844
+ this.delaysMs = delaysMs;
1845
+ this.wait = wait;
1846
+ this.budgetMs = budgetMs;
1847
+ this.now = now;
1848
+ }
1849
+ delaysMs;
1850
+ wait;
1851
+ budgetMs;
1852
+ now;
1853
+ static NONE = new _RetryPolicy([]);
1854
+ /** A platform restart or a short edge outage: no wait starts that would end past five minutes, so a step ends
1855
+ * within the budget plus one request timeout. */
1856
+ static FILING = new _RetryPolicy([250, 500, 1e3, 2e3, 4e3, 8e3, 16e3, 3e4], sleep, 3e5);
1857
+ static TRANSIENT_STATUSES = /* @__PURE__ */ new Set([502, 503, 504]);
1858
+ async run(attempt) {
1859
+ const started = this.now();
1860
+ for (let tries = 0; ; tries += 1) {
1861
+ const outcome = await Attempt.of(attempt);
1862
+ const delayMs = this.delaysMs[tries];
1863
+ const spent = delayMs === void 0 || this.now() - started + delayMs >= this.budgetMs;
1864
+ if (!outcome.transient || spent) return outcome.settle();
1865
+ await this.wait(delayMs);
1866
+ }
1867
+ }
1868
+ };
1869
+ var Attempt = class _Attempt {
1870
+ constructor(reply, error, transient) {
1871
+ this.reply = reply;
1872
+ this.error = error;
1873
+ this.transient = transient;
1874
+ }
1875
+ reply;
1876
+ error;
1877
+ transient;
1878
+ static async of(attempt) {
1879
+ try {
1880
+ const reply = await attempt();
1881
+ return new _Attempt(reply, null, RetryPolicy.TRANSIENT_STATUSES.has(reply.status));
1882
+ } catch (error) {
1883
+ return new _Attempt(null, error, error instanceof UnreachableError);
1884
+ }
1885
+ }
1886
+ settle() {
1887
+ if (this.reply) return this.reply;
1888
+ throw this.error;
1889
+ }
1890
+ };
1832
1891
  var PlatformTransport = class {
1833
1892
  constructor(endpoint, timeoutMs = platformTimeoutMs()) {
1834
1893
  this.endpoint = endpoint;
@@ -1842,6 +1901,9 @@ var PlatformTransport = class {
1842
1901
  }
1843
1902
  async send(method, route, body, opts = {}) {
1844
1903
  const timeoutMs = this.budget(opts.timeoutMs);
1904
+ return (opts.retry ?? RetryPolicy.NONE).run(() => this.once(method, route, body, timeoutMs));
1905
+ }
1906
+ async once(method, route, body, timeoutMs) {
1845
1907
  const payload = body === void 0 ? {} : { body: JSON.stringify(body) };
1846
1908
  const controller = new AbortController();
1847
1909
  const timer = setTimeout(() => controller.abort(), timeoutMs);
@@ -1924,7 +1986,7 @@ var MediaUploader = class _MediaUploader {
1924
1986
  put;
1925
1987
  maxBytes;
1926
1988
  /** The uploader for `GATEWAY_HOST` / `GATEWAY_PUBLIC_KEY` /
1927
- * `GATEWAY_SECRET_KEY` (the keys tracing exports with); null when any is unset. */
1989
+ * `GATEWAY_SECRET_KEY` only; null when any is unset, so a run traced with a saved login uploads none. */
1928
1990
  static fromEnv(env = process.env) {
1929
1991
  const host = env.GATEWAY_HOST;
1930
1992
  const publicKey = env.GATEWAY_PUBLIC_KEY;