@withgateway/sdk 0.2.6 → 0.2.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (110) hide show
  1. package/README.md +24 -8
  2. package/dist/cli.js +15468 -11263
  3. package/dist/cli.js.map +1 -1
  4. package/dist/cli.mjs +15233 -11028
  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 +291 -40
  9. package/dist/files/index.js.map +1 -1
  10. package/dist/files/index.mjs +284 -37
  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 +203 -47
  15. package/dist/hooks/index.js.map +1 -1
  16. package/dist/hooks/index.mjs +198 -42
  17. package/dist/hooks/index.mjs.map +1 -1
  18. package/dist/{index-BaKu5ZSU.d.mts → index-C3UzD0G3.d.mts} +75 -1
  19. package/dist/{index-BaKu5ZSU.d.ts → index-C3UzD0G3.d.ts} +75 -1
  20. package/dist/{index-CLkMr6VG.d.ts → index-D-_4Ibcn.d.ts} +36 -4
  21. package/dist/{index-CdbmO4aX.d.mts → index-FfK4Nump.d.mts} +36 -4
  22. package/dist/index.d.mts +3 -3
  23. package/dist/index.d.ts +3 -3
  24. package/dist/index.js +2149 -615
  25. package/dist/index.js.map +1 -1
  26. package/dist/index.mjs +2053 -566
  27. package/dist/index.mjs.map +1 -1
  28. package/dist/traces/index.js +268 -31
  29. package/dist/traces/index.js.map +1 -1
  30. package/dist/traces/index.mjs +262 -28
  31. package/dist/traces/index.mjs.map +1 -1
  32. package/dist/tracing/index.js +19 -11
  33. package/dist/tracing/index.js.map +1 -1
  34. package/dist/tracing/index.mjs +19 -11
  35. package/dist/tracing/index.mjs.map +1 -1
  36. package/dist/worlds/index.d.mts +886 -117
  37. package/dist/worlds/index.d.ts +886 -117
  38. package/dist/worlds/index.js +1770 -452
  39. package/dist/worlds/index.js.map +1 -1
  40. package/dist/worlds/index.mjs +1752 -434
  41. package/dist/worlds/index.mjs.map +1 -1
  42. package/package.json +14 -10
  43. package/runtime/gatewaysdk/environment/_toml.py +3 -10
  44. package/runtime/gatewaysdk/environment/_world.py +95 -28
  45. package/runtime/gatewaysdk/environment/runtime.py +10 -6
  46. package/runtime/gatewaysdk/environment/schema/__main__.py +35 -0
  47. package/runtime/gatewaysdk/environment/schema/api.py +19 -23
  48. package/runtime/gatewaysdk/environment/schema/batch.py +68 -14
  49. package/runtime/gatewaysdk/environment/schema/bundle_runtime.py +4 -2
  50. package/runtime/gatewaysdk/environment/schema/cast.py +264 -0
  51. package/runtime/gatewaysdk/environment/schema/compiler.py +35 -1
  52. package/runtime/gatewaysdk/environment/schema/conform.py +28 -10
  53. package/runtime/gatewaysdk/environment/schema/connector.py +59 -14
  54. package/runtime/gatewaysdk/environment/schema/connectors/custom/handlers.py +38 -1
  55. package/runtime/gatewaysdk/environment/schema/connectors/google-drive/readers/merge.toml +3 -1
  56. package/runtime/gatewaysdk/environment/schema/credentials.py +20 -0
  57. package/runtime/gatewaysdk/environment/schema/csv_rows.py +117 -0
  58. package/runtime/gatewaysdk/environment/schema/cycles.py +121 -0
  59. package/runtime/gatewaysdk/environment/schema/data.py +21 -5
  60. package/runtime/gatewaysdk/environment/schema/grading.py +95 -13
  61. package/runtime/gatewaysdk/environment/schema/handler_errors.py +44 -0
  62. package/runtime/gatewaysdk/environment/schema/handler_scan.py +175 -0
  63. package/runtime/gatewaysdk/environment/schema/host.py +68 -115
  64. package/runtime/gatewaysdk/environment/schema/host_requests.py +78 -0
  65. package/runtime/gatewaysdk/environment/schema/host_surfaces.py +12 -0
  66. package/runtime/gatewaysdk/environment/schema/ingest.py +5 -18
  67. package/runtime/gatewaysdk/environment/schema/local.py +7 -10
  68. package/runtime/gatewaysdk/environment/schema/openapi_document.py +322 -0
  69. package/runtime/gatewaysdk/environment/schema/openapi_import.py +382 -0
  70. package/runtime/gatewaysdk/environment/schema/openapi_routes.py +441 -0
  71. package/runtime/gatewaysdk/environment/schema/openapi_schemas.py +629 -0
  72. package/runtime/gatewaysdk/environment/schema/openapi_source.py +210 -0
  73. package/runtime/gatewaysdk/environment/schema/platform.py +110 -299
  74. package/runtime/gatewaysdk/environment/schema/platform_import.py +182 -0
  75. package/runtime/gatewaysdk/environment/schema/platform_query.py +95 -0
  76. package/runtime/gatewaysdk/environment/schema/route_bindings.py +176 -0
  77. package/runtime/gatewaysdk/environment/schema/runtime.py +56 -7
  78. package/runtime/gatewaysdk/environment/schema/scaffold.py +64 -5
  79. package/runtime/gatewaysdk/environment/schema/skills/benchmarks-getting-started/SKILL.md +70 -22
  80. package/runtime/gatewaysdk/environment/schema/skills/connector-schema-authoring/SKILL.md +54 -4
  81. package/runtime/gatewaysdk/environment/schema/skills/hooks-getting-started/SKILL.md +27 -2
  82. package/runtime/gatewaysdk/environment/schema/skills/world-data-ingestion/ROWS.md +62 -0
  83. package/runtime/gatewaysdk/environment/schema/skills/world-data-ingestion/SKILL.md +91 -54
  84. package/runtime/gatewaysdk/environment/schema/skills/worlds-getting-started/SKILL.md +146 -146
  85. package/runtime/gatewaysdk/environment/schema/skills/worlds-getting-started/references/cli-mcp-map.md +11 -7
  86. package/runtime/gatewaysdk/environment/schema/skills/worlds-getting-started/references/gotchas.md +30 -0
  87. package/runtime/gatewaysdk/environment/schema/skills/worlds-getting-started/references/new-world-sandbox.md +43 -0
  88. package/runtime/gatewaysdk/environment/schema/skills/worlds-getting-started/references/openapi-import.md +90 -0
  89. package/runtime/gatewaysdk/environment/schema/store.py +15 -6
  90. package/runtime/gatewaysdk/environment/schema/store_contract.py +119 -0
  91. package/runtime/gatewaysdk/environment/schema/tasks.py +121 -32
  92. package/runtime/gatewaysdk/environment/schema/tools_world.py +32 -10
  93. package/runtime/gatewaysdk/environment/schema/tree_import.py +228 -0
  94. package/runtime/gatewaysdk/environment/schema/ui.py +18 -2
  95. package/runtime/gatewaysdk/environment/schema/validation.py +35 -0
  96. package/runtime/gatewaysdk/environment/schema/verbs.py +8 -2
  97. package/runtime/gatewaysdk/environment/world.py +42 -3
  98. package/runtime/gatewaysdk/environment/world_session_contract.py +57 -0
  99. package/skills/benchmarks-getting-started/SKILL.md +70 -22
  100. package/skills/connector-schema-authoring/SKILL.md +54 -4
  101. package/skills/connector-schema-authoring/connector-worlds.md +21 -7
  102. package/skills/connector-schema-authoring/world-schema.md +144 -83
  103. package/skills/hooks-getting-started/SKILL.md +27 -2
  104. package/skills/world-data-ingestion/ROWS.md +62 -0
  105. package/skills/world-data-ingestion/SKILL.md +91 -54
  106. package/skills/worlds-getting-started/SKILL.md +146 -146
  107. package/skills/worlds-getting-started/references/cli-mcp-map.md +11 -7
  108. package/skills/worlds-getting-started/references/gotchas.md +30 -0
  109. package/skills/worlds-getting-started/references/new-world-sandbox.md +43 -0
  110. package/skills/worlds-getting-started/references/openapi-import.md +90 -0
@@ -1,2 +1,2 @@
1
1
  import '../worlds/index.mjs';
2
- export { D as DRIVE_PREFIX, a as DriveDownload, b as DriveFile, c as DriveFolder, d as DriveListing, F as FileConnector, U as UploadOptions, e as UploadResult, f as confirmUpload, g as contentTypeFor, h as createFolder, j as deleteFile, k as downloadFile, l as drivePath, m as getFile, n as isDriveRef, o as iterateFiles, p as listFileConnectors, q as listFiles, r as moveFile, s as readFile, t as requestUpload, u as sha256Base64, v as syncFileConnector, w as uploadBytes, x as uploadFile } from '../index-CdbmO4aX.mjs';
2
+ export { D as DRIVE_PREFIX, a as DriveDownload, b as DriveFile, c as DriveFolder, d as DriveListing, F as FetchHeader, e as FetchToDriveOptions, f as FetchToDriveResult, g as FileConnector, U as UploadOptions, h as UploadResult, j as confirmUpload, k as contentTypeFor, l as createFolder, m as deleteFile, n as downloadFile, o as drivePath, p as fetchToDrive, q as getFile, r as isDriveRef, s as iterateFiles, t as listFileConnectors, u as listFiles, v as moveFile, w as readFile, x as requestUpload, y as sha256Base64, z as syncFileConnector, A as uploadBytes, B as uploadFile } from '../index-FfK4Nump.mjs';
@@ -1,2 +1,2 @@
1
1
  import '../worlds/index.js';
2
- export { D as DRIVE_PREFIX, a as DriveDownload, b as DriveFile, c as DriveFolder, d as DriveListing, F as FileConnector, U as UploadOptions, e as UploadResult, f as confirmUpload, g as contentTypeFor, h as createFolder, j as deleteFile, k as downloadFile, l as drivePath, m as getFile, n as isDriveRef, o as iterateFiles, p as listFileConnectors, q as listFiles, r as moveFile, s as readFile, t as requestUpload, u as sha256Base64, v as syncFileConnector, w as uploadBytes, x as uploadFile } from '../index-CLkMr6VG.js';
2
+ export { D as DRIVE_PREFIX, a as DriveDownload, b as DriveFile, c as DriveFolder, d as DriveListing, F as FetchHeader, e as FetchToDriveOptions, f as FetchToDriveResult, g as FileConnector, U as UploadOptions, h as UploadResult, j as confirmUpload, k as contentTypeFor, l as createFolder, m as deleteFile, n as downloadFile, o as drivePath, p as fetchToDrive, q as getFile, r as isDriveRef, s as iterateFiles, t as listFileConnectors, u as listFiles, v as moveFile, w as readFile, x as requestUpload, y as sha256Base64, z as syncFileConnector, A as uploadBytes, B as uploadFile } from '../index-D-_4Ibcn.js';
@@ -5,8 +5,13 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
6
  var __getProtoOf = Object.getPrototypeOf;
7
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __esm = (fn, res) => function __init() {
9
- return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
8
+ var __esm = (fn, res, err) => function __init() {
9
+ if (err) throw err[0];
10
+ try {
11
+ return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
12
+ } catch (e) {
13
+ throw err = [e], e;
14
+ }
10
15
  };
11
16
  var __export = (target, all) => {
12
17
  for (var name in all)
@@ -30,11 +35,147 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
30
35
  ));
31
36
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
32
37
 
38
+ // src/worlds/transport.ts
39
+ function platformTimeoutMs(env = process.env) {
40
+ const raw = env[PLATFORM_TIMEOUT_ENV];
41
+ if (raw === void 0 || raw === "") return PLATFORM_TIMEOUT_DEFAULT_MS;
42
+ const value = Number(raw);
43
+ if (Number.isInteger(value) && value > 0) return value;
44
+ throw new Error(`${PLATFORM_TIMEOUT_ENV} must be a positive whole number of milliseconds, not \`${raw}\`.`);
45
+ }
46
+ var PLATFORM_TIMEOUT_ENV, PLATFORM_TIMEOUT_DEFAULT_MS, CHECK_HOST, RETRY, CAUSES, UNKNOWN_CAUSE, TransportCause, UnreachableError, PlatformTransport;
47
+ var init_transport = __esm({
48
+ "src/worlds/transport.ts"() {
49
+ "use strict";
50
+ PLATFORM_TIMEOUT_ENV = "GATEWAY_TIMEOUT_MS";
51
+ PLATFORM_TIMEOUT_DEFAULT_MS = 12e4;
52
+ CHECK_HOST = "Check GATEWAY_HOST (or --host) points at a running platform, then retry.";
53
+ RETRY = "Retry; if it repeats, check the network between here and the platform.";
54
+ CAUSES = {
55
+ ECONNREFUSED: { reason: "connection refused", next: CHECK_HOST },
56
+ ENOTFOUND: { reason: "DNS lookup failed", next: CHECK_HOST },
57
+ EAI_AGAIN: { reason: "DNS lookup failed", next: CHECK_HOST },
58
+ ETIMEDOUT: { reason: "connect timed out", next: CHECK_HOST },
59
+ UND_ERR_CONNECT_TIMEOUT: { reason: "connect timed out", next: CHECK_HOST },
60
+ EHOSTUNREACH: { reason: "host unreachable", next: CHECK_HOST },
61
+ ENETUNREACH: { reason: "network unreachable", next: RETRY },
62
+ ECONNRESET: { reason: "connection dropped", next: RETRY },
63
+ UND_ERR_SOCKET: { reason: "connection dropped", next: RETRY },
64
+ EPIPE: { reason: "connection dropped", next: RETRY }
65
+ };
66
+ UNKNOWN_CAUSE = { reason: "network error", next: CHECK_HOST };
67
+ TransportCause = class _TransportCause {
68
+ constructor(reason, detail, next) {
69
+ this.reason = reason;
70
+ this.detail = detail;
71
+ this.next = next;
72
+ }
73
+ reason;
74
+ detail;
75
+ next;
76
+ static timeout(timeoutMs) {
77
+ return new _TransportCause(
78
+ `timed out after ${timeoutMs / 1e3}s`,
79
+ null,
80
+ `Retry; if the platform is slow, raise ${PLATFORM_TIMEOUT_ENV} (milliseconds per request).`
81
+ );
82
+ }
83
+ static of(error) {
84
+ const cause = error instanceof Error && error.cause instanceof Error ? error.cause : void 0;
85
+ const code = cause && "code" in cause && typeof cause.code === "string" ? cause.code : null;
86
+ const message = cause?.message ?? (error instanceof Error ? error.message : String(error));
87
+ const known = code && CAUSES[code] || UNKNOWN_CAUSE;
88
+ return new _TransportCause(known.reason, code ? `${code}: ${message}` : message, known.next);
89
+ }
90
+ describe() {
91
+ return this.detail === null ? this.reason : `${this.reason} (${this.detail})`;
92
+ }
93
+ };
94
+ UnreachableError = class extends Error {
95
+ constructor(host, method, route, failure) {
96
+ super(`${method} ${route}: no answer from ${host}: ${failure.describe()}. ${failure.next}`);
97
+ this.host = host;
98
+ this.method = method;
99
+ this.route = route;
100
+ this.failure = failure;
101
+ this.name = "UnreachableError";
102
+ }
103
+ host;
104
+ method;
105
+ route;
106
+ failure;
107
+ };
108
+ PlatformTransport = class {
109
+ constructor(endpoint, timeoutMs = platformTimeoutMs()) {
110
+ this.endpoint = endpoint;
111
+ this.timeoutMs = timeoutMs;
112
+ }
113
+ endpoint;
114
+ timeoutMs;
115
+ /** A request that legitimately takes longer (a sandbox exec, a world create) waits its own budget; every other one waits the default. */
116
+ budget(ownMs) {
117
+ return Math.max(ownMs ?? 0, this.timeoutMs);
118
+ }
119
+ async send(method, route, body, opts = {}) {
120
+ const timeoutMs = this.budget(opts.timeoutMs);
121
+ const payload = body === void 0 ? {} : { body: JSON.stringify(body) };
122
+ const controller = new AbortController();
123
+ const timer = setTimeout(() => controller.abort(), timeoutMs);
124
+ try {
125
+ const res = await fetch(`${this.endpoint.host}${route}`, {
126
+ method,
127
+ headers: {
128
+ "content-type": "application/json",
129
+ accept: "application/json",
130
+ authorization: "Basic " + Buffer.from(`${this.endpoint.publicKey}:${this.endpoint.secretKey}`).toString("base64")
131
+ },
132
+ ...payload,
133
+ signal: controller.signal
134
+ });
135
+ return { status: res.status, ok: res.ok, text: await res.text() };
136
+ } catch (error) {
137
+ const cause = controller.signal.aborted ? TransportCause.timeout(timeoutMs) : TransportCause.of(error);
138
+ throw new UnreachableError(this.endpoint.host, method, route, cause);
139
+ } finally {
140
+ clearTimeout(timer);
141
+ }
142
+ }
143
+ };
144
+ }
145
+ });
146
+
147
+ // src/worlds/browserReconnect.ts
148
+ var init_browserReconnect = __esm({
149
+ "src/worlds/browserReconnect.ts"() {
150
+ "use strict";
151
+ }
152
+ });
153
+
33
154
  // src/worlds/browser.ts
34
155
  var init_browser = __esm({
35
156
  "src/worlds/browser.ts"() {
36
157
  "use strict";
37
158
  init_session();
159
+ init_browserReconnect();
160
+ }
161
+ });
162
+
163
+ // src/worlds/sessionContract.ts
164
+ var CALL_BODY_LIMIT_BYTES, EXPLORATORY_TASK;
165
+ var init_sessionContract = __esm({
166
+ "src/worlds/sessionContract.ts"() {
167
+ "use strict";
168
+ CALL_BODY_LIMIT_BYTES = 4 * 1024 * 1024;
169
+ EXPLORATORY_TASK = Object.freeze({
170
+ instruction: "exploratory session"
171
+ });
172
+ }
173
+ });
174
+
175
+ // src/worlds/taskRef.ts
176
+ var init_taskRef = __esm({
177
+ "src/worlds/taskRef.ts"() {
178
+ "use strict";
38
179
  }
39
180
  });
40
181
 
@@ -46,12 +187,23 @@ var init_session = __esm({
46
187
  import_node_crypto = require("crypto");
47
188
  init_worlds();
48
189
  init_browser();
190
+ init_sessionContract();
191
+ init_taskRef();
192
+ init_taskRef();
49
193
  READY_TIMEOUT_MS = 10 * 6e4;
50
194
  CALL_TIMEOUT_MS = 3 * 6e4;
51
195
  JUDGED_GRADE_TIMEOUT_MS = 15 * 6e4;
52
196
  }
53
197
  });
54
198
 
199
+ // src/worlds/sessionList.ts
200
+ var init_sessionList = __esm({
201
+ "src/worlds/sessionList.ts"() {
202
+ "use strict";
203
+ init_worlds();
204
+ }
205
+ });
206
+
55
207
  // src/worlds/tasks.ts
56
208
  var init_tasks = __esm({
57
209
  "src/worlds/tasks.ts"() {
@@ -93,32 +245,74 @@ var init_taskRun = __esm({
93
245
  }
94
246
  });
95
247
 
248
+ // src/worlds/checkoutProvenance.ts
249
+ var import_node_child_process;
250
+ var init_checkoutProvenance = __esm({
251
+ "src/worlds/checkoutProvenance.ts"() {
252
+ "use strict";
253
+ import_node_child_process = require("child_process");
254
+ }
255
+ });
256
+
257
+ // src/worlds/setRun.ts
258
+ var init_setRun = __esm({
259
+ "src/worlds/setRun.ts"() {
260
+ "use strict";
261
+ init_worlds();
262
+ init_checkoutProvenance();
263
+ init_taskRun();
264
+ }
265
+ });
266
+
267
+ // src/worlds/checkoutTarget.ts
268
+ var fs2, path2;
269
+ var init_checkoutTarget = __esm({
270
+ "src/worlds/checkoutTarget.ts"() {
271
+ "use strict";
272
+ fs2 = __toESM(require("fs"));
273
+ path2 = __toESM(require("path"));
274
+ }
275
+ });
276
+
96
277
  // src/worlds/worldDir.ts
97
- var import_node_crypto3, fs2, path2, CONNECTOR_SPEC, WORLD_SCHEMA_MARKERS, WORLD_ROOT_MARKERS;
278
+ var import_node_crypto3, fs3, path3, CONNECTOR_SPEC, WORLD_SCHEMA_MARKERS, WORLD_ROOT_MARKERS;
98
279
  var init_worldDir = __esm({
99
280
  "src/worlds/worldDir.ts"() {
100
281
  "use strict";
101
282
  import_node_crypto3 = require("crypto");
102
- fs2 = __toESM(require("fs"));
103
- path2 = __toESM(require("path"));
283
+ fs3 = __toESM(require("fs"));
284
+ path3 = __toESM(require("path"));
104
285
  CONNECTOR_SPEC = "connector.toml";
105
286
  WORLD_SCHEMA_MARKERS = ["schema/world.json", "schema/runtime.json", "schema/lock.json"];
106
287
  WORLD_ROOT_MARKERS = [CONNECTOR_SPEC, ...WORLD_SCHEMA_MARKERS];
107
288
  }
108
289
  });
109
290
 
291
+ // src/worlds/tar.ts
292
+ var fs4, path4, import_node_zlib;
293
+ var init_tar = __esm({
294
+ "src/worlds/tar.ts"() {
295
+ "use strict";
296
+ fs4 = __toESM(require("fs"));
297
+ path4 = __toESM(require("path"));
298
+ import_node_zlib = require("zlib");
299
+ }
300
+ });
301
+
110
302
  // src/worlds/hub.ts
111
- var import_node_crypto4, import_node_zlib, fs3, path3, META_RELPATH;
303
+ var import_node_crypto4, import_node_zlib2, fs5, path5, META_RELPATH;
112
304
  var init_hub = __esm({
113
305
  "src/worlds/hub.ts"() {
114
306
  "use strict";
115
307
  import_node_crypto4 = require("crypto");
116
- import_node_zlib = require("zlib");
117
- fs3 = __toESM(require("fs"));
118
- path3 = __toESM(require("path"));
308
+ import_node_zlib2 = require("zlib");
309
+ fs5 = __toESM(require("fs"));
310
+ path5 = __toESM(require("path"));
119
311
  init_worlds();
312
+ init_checkoutTarget();
120
313
  init_worldDir();
121
- META_RELPATH = path3.join(".gateway", ".env-metadata.json");
314
+ init_tar();
315
+ META_RELPATH = path5.join(".gateway", ".env-metadata.json");
122
316
  }
123
317
  });
124
318
 
@@ -131,11 +325,20 @@ var init_validate = __esm({
131
325
  }
132
326
  });
133
327
 
328
+ // src/worlds/sandbox.ts
329
+ var init_sandbox = __esm({
330
+ "src/worlds/sandbox.ts"() {
331
+ "use strict";
332
+ init_worlds();
333
+ }
334
+ });
335
+
134
336
  // src/worlds/describe.ts
135
337
  var init_describe = __esm({
136
338
  "src/worlds/describe.ts"() {
137
339
  "use strict";
138
340
  init_worlds();
341
+ init_sandbox();
139
342
  }
140
343
  });
141
344
 
@@ -214,20 +417,28 @@ var init_migrate = __esm({
214
417
  });
215
418
 
216
419
  // src/worlds/ingest.ts
217
- var fs4, os, path4;
420
+ var fs6, os, path6;
218
421
  var init_ingest = __esm({
219
422
  "src/worlds/ingest.ts"() {
220
423
  "use strict";
221
- fs4 = __toESM(require("fs"));
424
+ fs6 = __toESM(require("fs"));
222
425
  os = __toESM(require("os"));
223
- path4 = __toESM(require("path"));
426
+ path6 = __toESM(require("path"));
224
427
  init_worlds();
225
428
  }
226
429
  });
227
430
 
228
- // src/worlds/sandbox.ts
229
- var init_sandbox = __esm({
230
- "src/worlds/sandbox.ts"() {
431
+ // src/worlds/editSessions.ts
432
+ var init_editSessions = __esm({
433
+ "src/worlds/editSessions.ts"() {
434
+ "use strict";
435
+ init_worlds();
436
+ }
437
+ });
438
+
439
+ // src/worlds/dryRun.ts
440
+ var init_dryRun = __esm({
441
+ "src/worlds/dryRun.ts"() {
231
442
  "use strict";
232
443
  init_worlds();
233
444
  }
@@ -245,30 +456,48 @@ function resolveEnv(options) {
245
456
  }
246
457
  return { host: host.replace(/\/+$/, ""), publicKey, secretKey };
247
458
  }
248
- async function apiRequest(options, method, path6, body) {
249
- const { host, publicKey, secretKey } = resolveEnv(options);
250
- const res = await fetch(`${host}${path6}`, {
251
- method,
252
- headers: {
253
- "content-type": "application/json",
254
- authorization: "Basic " + Buffer.from(`${publicKey}:${secretKey}`).toString("base64")
255
- },
256
- ...body === void 0 ? {} : { body: JSON.stringify(body) }
257
- });
258
- const text = await res.text();
259
- if (!res.ok) throw new ApiError(res.status, method, path6, text.slice(0, 400));
260
- return JSON.parse(text);
459
+ function parseErrorBody(text, limit = 600) {
460
+ const raw = { detail: text.slice(0, limit), code: null };
461
+ let parsed;
462
+ try {
463
+ parsed = JSON.parse(text);
464
+ } catch {
465
+ return raw;
466
+ }
467
+ if (parsed === null || typeof parsed !== "object") return raw;
468
+ const { message, code } = parsed;
469
+ const stableCode = typeof code === "string" ? code : null;
470
+ if (typeof message !== "string") return { ...raw, code: stableCode };
471
+ if (stableCode === null)
472
+ return { detail: message.slice(0, limit), code: null };
473
+ return {
474
+ detail: `${message} (${stableCode})`.slice(0, limit),
475
+ code: stableCode
476
+ };
477
+ }
478
+ async function apiRequest(options, method, path8, body, init = {}) {
479
+ const reply = await new PlatformTransport(resolveEnv(options)).send(method, path8, body, init);
480
+ if (!reply.ok) throw new ApiError(reply.status, method, path8, reply.text);
481
+ return JSON.parse(reply.text);
261
482
  }
262
483
  var ApiError;
263
484
  var init_worlds = __esm({
264
485
  "src/worlds/index.ts"() {
265
486
  "use strict";
487
+ init_transport();
488
+ init_transport();
266
489
  init_session();
490
+ init_sessionList();
491
+ init_sessionContract();
492
+ init_taskRef();
267
493
  init_tasks();
268
494
  init_taskSessions();
269
495
  init_taskRun();
496
+ init_setRun();
497
+ init_checkoutProvenance();
270
498
  init_evals();
271
499
  init_browser();
500
+ init_browserReconnect();
272
501
  init_hub();
273
502
  init_validate();
274
503
  init_describe();
@@ -278,12 +507,20 @@ var init_worlds = __esm({
278
507
  init_migrate();
279
508
  init_ingest();
280
509
  init_sandbox();
510
+ init_editSessions();
511
+ init_dryRun();
281
512
  ApiError = class extends Error {
282
- constructor(status, method, path6, body) {
283
- super(`${method} ${path6} -> ${status}: ${body}`);
513
+ constructor(status, method, path8, text) {
514
+ const parsed = parseErrorBody(text);
515
+ super(`${method} ${path8} -> ${status}: ${parsed.detail}`);
284
516
  this.status = status;
517
+ this.text = text;
285
518
  this.name = "ApiError";
519
+ this.code = parsed.code;
286
520
  }
521
+ status;
522
+ text;
523
+ code;
287
524
  };
288
525
  }
289
526
  });
@@ -298,6 +535,7 @@ __export(files_exports, {
298
535
  deleteFile: () => deleteFile,
299
536
  downloadFile: () => downloadFile,
300
537
  drivePath: () => drivePath,
538
+ fetchToDrive: () => fetchToDrive,
301
539
  getFile: () => getFile,
302
540
  isDriveRef: () => isDriveRef,
303
541
  iterateFiles: () => iterateFiles,
@@ -313,8 +551,8 @@ __export(files_exports, {
313
551
  });
314
552
  module.exports = __toCommonJS(files_exports);
315
553
  var import_node_crypto7 = require("crypto");
316
- var fs5 = __toESM(require("fs"));
317
- var path5 = __toESM(require("path"));
554
+ var fs7 = __toESM(require("fs"));
555
+ var path7 = __toESM(require("path"));
318
556
  var import_node_stream = require("stream");
319
557
  var import_promises = require("stream/promises");
320
558
  init_worlds();
@@ -355,17 +593,20 @@ async function openDownload(url) {
355
593
  if (!res.ok || !res.body) throw new Error(`download failed: storage answered HTTP ${res.status}`);
356
594
  return res;
357
595
  }
358
- async function readFile(options = {}, filePath) {
596
+ async function readFile(options = {}, filePath, limits = {}) {
359
597
  const file = await getFile(options, filePath);
598
+ const size = file.sizeBytes ?? 0;
599
+ if (limits.maxBytes !== void 0 && size > limits.maxBytes)
600
+ throw new Error(`${filePath} is ${size} bytes, over the ${limits.maxBytes}-byte limit`);
360
601
  const res = await openDownload(file.url);
361
602
  return Buffer.from(await res.arrayBuffer());
362
603
  }
363
604
  async function downloadFile(options = {}, filePath, outPath, onProgress) {
364
605
  const file = await getFile(options, filePath);
365
606
  const res = await openDownload(file.url);
366
- fs5.mkdirSync(path5.dirname(path5.resolve(outPath)), { recursive: true });
607
+ fs7.mkdirSync(path7.dirname(path7.resolve(outPath)), { recursive: true });
367
608
  const source = import_node_stream.Readable.fromWeb(res.body);
368
- await (0, import_promises.pipeline)(source, counting((n) => onProgress?.(n, file.sizeBytes)), fs5.createWriteStream(outPath));
609
+ await (0, import_promises.pipeline)(source, counting((n) => onProgress?.(n, file.sizeBytes)), fs7.createWriteStream(outPath));
369
610
  return { ...file, out: outPath };
370
611
  }
371
612
  async function requestUpload(options = {}, body) {
@@ -376,7 +617,7 @@ async function confirmUpload(options = {}, fileId, ok = true) {
376
617
  }
377
618
  async function sha256Base64(localPath) {
378
619
  const hash = (0, import_node_crypto7.createHash)("sha256");
379
- for await (const chunk of fs5.createReadStream(localPath)) hash.update(chunk);
620
+ for await (const chunk of fs7.createReadStream(localPath)) hash.update(chunk);
380
621
  return hash.digest("base64");
381
622
  }
382
623
  var CONTENT_TYPES = {
@@ -412,7 +653,7 @@ var CONTENT_TYPES = {
412
653
  ".mp4": "video/mp4"
413
654
  };
414
655
  function contentTypeFor(name) {
415
- return CONTENT_TYPES[path5.extname(name).toLowerCase()] ?? "application/octet-stream";
656
+ return CONTENT_TYPES[path7.extname(name).toLowerCase()] ?? "application/octet-stream";
416
657
  }
417
658
  function counting(report) {
418
659
  let seen = 0;
@@ -439,7 +680,7 @@ async function putPresigned(uploadUrl, body, headers) {
439
680
  if (!res.ok) throw new Error(`upload failed: storage answered HTTP ${res.status}: ${(await res.text()).slice(0, 300)}`);
440
681
  }
441
682
  async function uploadFile(options = {}, localPath, targetPath, upload = {}) {
442
- const stat = fs5.statSync(localPath);
683
+ const stat = fs7.statSync(localPath);
443
684
  if (!stat.isFile()) throw new Error(`${localPath} is not a file`);
444
685
  if (stat.size === 0) throw new Error(`${localPath} is empty; the drive refuses zero-byte uploads`);
445
686
  const contentType = upload.contentType ?? contentTypeFor(localPath);
@@ -447,7 +688,7 @@ async function uploadFile(options = {}, localPath, targetPath, upload = {}) {
447
688
  const target = drivePath(targetPath);
448
689
  const granted = await requestUpload(options, { path: target, contentLength: stat.size, contentType, sha256, ...upload.overwrite ? { overwrite: true } : {} });
449
690
  try {
450
- const stream = fs5.createReadStream(localPath).pipe(counting((n) => upload.onProgress?.(n, stat.size)));
691
+ const stream = fs7.createReadStream(localPath).pipe(counting((n) => upload.onProgress?.(n, stat.size)));
451
692
  await putPresigned(granted.uploadUrl, import_node_stream.Readable.toWeb(stream), { contentType, contentLength: stat.size, sha256 });
452
693
  } catch (error) {
453
694
  await confirmUpload(options, granted.fileId, false).catch(() => void 0);
@@ -477,6 +718,15 @@ async function deleteFile(options = {}, filePath) {
477
718
  async function moveFile(options = {}, fromPath, toPath) {
478
719
  return apiRequest(options, "POST", `${BASE}/move`, { fromPath: drivePath(fromPath), toPath: drivePath(toPath) });
479
720
  }
721
+ async function fetchToDrive(options = {}, url, targetPath, fetchOptions = {}) {
722
+ return apiRequest(options, "POST", `${BASE}/fetch`, {
723
+ url,
724
+ path: drivePath(targetPath),
725
+ ...fetchOptions.headers?.length ? { headers: fetchOptions.headers } : {},
726
+ ...fetchOptions.contentType ? { contentType: fetchOptions.contentType } : {},
727
+ ...fetchOptions.overwrite ? { overwrite: true } : {}
728
+ });
729
+ }
480
730
  async function createFolder(options = {}, folderPath) {
481
731
  return apiRequest(options, "POST", `${BASE}/folders`, { path: drivePath(folderPath) });
482
732
  }
@@ -495,6 +745,7 @@ async function syncFileConnector(options = {}, connectorId) {
495
745
  deleteFile,
496
746
  downloadFile,
497
747
  drivePath,
748
+ fetchToDrive,
498
749
  getFile,
499
750
  isDriveRef,
500
751
  iterateFiles,