@withgateway/sdk 0.2.5 → 0.2.6

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 (75) hide show
  1. package/dist/cli.js +3121 -1283
  2. package/dist/cli.js.map +1 -1
  3. package/dist/cli.mjs +3185 -1347
  4. package/dist/cli.mjs.map +1 -1
  5. package/dist/files/index.js +9 -0
  6. package/dist/files/index.js.map +1 -1
  7. package/dist/files/index.mjs +9 -0
  8. package/dist/files/index.mjs.map +1 -1
  9. package/dist/hooks/index.d.mts +1 -1
  10. package/dist/hooks/index.d.ts +1 -1
  11. package/dist/hooks/index.js +280 -8
  12. package/dist/hooks/index.js.map +1 -1
  13. package/dist/hooks/index.mjs +272 -8
  14. package/dist/hooks/index.mjs.map +1 -1
  15. package/dist/{index-1xnxt0Cc.d.ts → index-BO2SNSgy.d.ts} +12 -1
  16. package/dist/{index-B0R3IgsV.d.mts → index-BaKu5ZSU.d.mts} +124 -2
  17. package/dist/{index-B0R3IgsV.d.ts → index-BaKu5ZSU.d.ts} +124 -2
  18. package/dist/{index-C1wDEwH4.d.mts → index-Cz8Q6Keo.d.mts} +12 -1
  19. package/dist/index.d.mts +4 -4
  20. package/dist/index.d.ts +4 -4
  21. package/dist/index.js +726 -167
  22. package/dist/index.js.map +1 -1
  23. package/dist/index.mjs +718 -167
  24. package/dist/index.mjs.map +1 -1
  25. package/dist/traces/index.js +9 -0
  26. package/dist/traces/index.js.map +1 -1
  27. package/dist/traces/index.mjs +9 -0
  28. package/dist/traces/index.mjs.map +1 -1
  29. package/dist/tracing/index.d.mts +1 -1
  30. package/dist/tracing/index.d.ts +1 -1
  31. package/dist/tracing/index.js +97 -61
  32. package/dist/tracing/index.js.map +1 -1
  33. package/dist/tracing/index.mjs +97 -61
  34. package/dist/tracing/index.mjs.map +1 -1
  35. package/dist/worlds/index.d.mts +154 -4
  36. package/dist/worlds/index.d.ts +154 -4
  37. package/dist/worlds/index.js +348 -97
  38. package/dist/worlds/index.js.map +1 -1
  39. package/dist/worlds/index.mjs +348 -97
  40. package/dist/worlds/index.mjs.map +1 -1
  41. package/package.json +1 -1
  42. package/runtime/gatewaysdk/environment/_bundle.py +1 -1
  43. package/runtime/gatewaysdk/environment/_materialize.py +53 -9
  44. package/runtime/gatewaysdk/environment/_toml.py +13 -0
  45. package/runtime/gatewaysdk/environment/schema/api.py +3 -7
  46. package/runtime/gatewaysdk/environment/schema/batch.py +15 -11
  47. package/runtime/gatewaysdk/environment/schema/bundle_runtime.py +24 -0
  48. package/runtime/gatewaysdk/environment/schema/compiler.py +60 -28
  49. package/runtime/gatewaysdk/environment/schema/conform.py +1 -1
  50. package/runtime/gatewaysdk/environment/schema/connector.py +1 -1
  51. package/runtime/gatewaysdk/environment/schema/connectors/google-drive/readers/merge.ingest.toml +25 -0
  52. package/runtime/gatewaysdk/environment/schema/connectors/google-drive/readers/merge.toml +17 -0
  53. package/runtime/gatewaysdk/environment/schema/extract.py +1 -5
  54. package/runtime/gatewaysdk/environment/schema/host_surfaces.py +1 -5
  55. package/runtime/gatewaysdk/environment/schema/mapping.py +1 -1
  56. package/runtime/gatewaysdk/environment/schema/platform.py +16 -4
  57. package/runtime/gatewaysdk/environment/schema/redaction.py +1 -1
  58. package/runtime/gatewaysdk/environment/schema/scaffold.py +9 -2
  59. package/runtime/gatewaysdk/environment/schema/skills/benchmarks-getting-started/SKILL.md +67 -9
  60. package/runtime/gatewaysdk/environment/schema/skills/hooks-getting-started/SKILL.md +61 -2
  61. package/runtime/gatewaysdk/environment/schema/skills/world-data-ingestion/SKILL.md +4 -1
  62. package/runtime/gatewaysdk/environment/schema/skills/worlds-getting-started/SKILL.md +11 -11
  63. package/runtime/gatewaysdk/environment/schema/skills/worlds-getting-started/references/cli-mcp-map.md +17 -1
  64. package/runtime/gatewaysdk/environment/schema/snapshot.py +1 -5
  65. package/runtime/gatewaysdk/environment/schema/tools_world.py +1 -5
  66. package/runtime/gatewaysdk/environment/schema/ui.py +1 -5
  67. package/runtime/gatewaysdk/environment/schema/world_tests.py +1 -1
  68. package/runtime/gatewaysdk/environment/world.py +120 -4
  69. package/skills/benchmarks-getting-started/SKILL.md +67 -9
  70. package/skills/connector-schema-authoring/connector-worlds.md +8 -1
  71. package/skills/connector-schema-authoring/world-schema.md +1 -1
  72. package/skills/hooks-getting-started/SKILL.md +61 -2
  73. package/skills/world-data-ingestion/SKILL.md +4 -1
  74. package/skills/worlds-getting-started/SKILL.md +11 -11
  75. package/skills/worlds-getting-started/references/cli-mcp-map.md +17 -1
package/dist/index.mjs CHANGED
@@ -1029,8 +1029,8 @@ async function runSessions(opts) {
1029
1029
  let tasks = opts.tasks;
1030
1030
  let versionId = opts.versionId;
1031
1031
  if (!tasks || !versionId) {
1032
- const { openWorld: openWorld2 } = await Promise.resolve().then(() => (init_worlds(), worlds_exports));
1033
- const world = await openWorld2(opts.world, options);
1032
+ const { openWorld: openWorld2, openWorldVersion: openWorldVersion2 } = await Promise.resolve().then(() => (init_worlds(), worlds_exports));
1033
+ const world = versionId ? await openWorldVersion2(opts.world.split("@", 1)[0], versionId, options) : await openWorld2(opts.world, options);
1034
1034
  tasks = tasks ?? world.tasks.map((t) => t.name);
1035
1035
  versionId = versionId ?? world.version.versionId;
1036
1036
  }
@@ -1086,10 +1086,12 @@ async function runSessions(opts) {
1086
1086
  })
1087
1087
  );
1088
1088
  const mean = results.reduce((sum, r) => sum + (r.reward ?? 0), 0) / (results.length || 1);
1089
+ const failed = results.filter((r) => r.error).length;
1089
1090
  return {
1090
1091
  results: results.sort((a, b) => a.task.localeCompare(b.task)),
1091
1092
  mean,
1092
- passed: opts.failUnder === void 0 ? true : mean >= opts.failUnder
1093
+ failed,
1094
+ passed: failed === 0 && (opts.failUnder === void 0 || mean >= opts.failUnder)
1093
1095
  };
1094
1096
  }
1095
1097
  var isTaskIdRef, isTaskSpec, taskLabel, READY_TIMEOUT_MS, READY_POLL_MS, CALL_TIMEOUT_MS, CALL_POLL_MS, JUDGED_GRADE_TIMEOUT_MS, JUDGED_GRADE_POLL_MS, EXPORT_PAGE, sleep2, modelToolName, WorldSessionTimeout, WorldSessionCallError, WorldSession;
@@ -1987,7 +1989,7 @@ var require_package = __commonJS({
1987
1989
  "package.json"(exports, module) {
1988
1990
  module.exports = {
1989
1991
  name: "@withgateway/sdk",
1990
- version: "0.2.5",
1992
+ version: "0.2.6",
1991
1993
  description: "Gateway SDK for TypeScript - A/B experiments, tracing, and observability",
1992
1994
  main: "./dist/index.js",
1993
1995
  module: "./dist/index.mjs",
@@ -2810,7 +2812,7 @@ async function fileTaskRun(live, runId, model, report, grade, agentError, traced
2810
2812
  task: live.name ?? live.taskId ?? runId,
2811
2813
  rolloutIndex: 0,
2812
2814
  prompt: live.instruction,
2813
- completion: report,
2815
+ ...report === null ? {} : { completion: report },
2814
2816
  rewards: grade.rewards,
2815
2817
  info: {
2816
2818
  sessionId: runId,
@@ -2848,17 +2850,20 @@ async function fileTaskRun(live, runId, model, report, grade, agentError, traced
2848
2850
  return evaluationId;
2849
2851
  }
2850
2852
  function reportFromResult(result) {
2853
+ if (result === void 0 || result === null)
2854
+ return { report: null, extra: {} };
2851
2855
  if (typeof result === "string") return { report: result, extra: {} };
2852
- if (result && typeof result === "object") {
2853
- const { report, ...extra } = result;
2854
- return {
2855
- report: report === void 0 || report === null ? null : typeof report === "string" ? report : String(report),
2856
- extra
2857
- };
2858
- }
2859
- if (result !== void 0 && result !== null)
2860
- return { report: String(result), extra: {} };
2861
- return { report: null, extra: {} };
2856
+ if (typeof result !== "object" || Array.isArray(result))
2857
+ throw new Error(
2858
+ `agent returned ${describeValue(result)}; ${RESULT_CONTRACT}`
2859
+ );
2860
+ const { report, ...extra } = result;
2861
+ if (report === void 0 || report === null) return { report: null, extra };
2862
+ if (typeof report !== "string")
2863
+ throw new Error(
2864
+ `agent returned a report of type ${describeValue(report)}; ${RESULT_CONTRACT}`
2865
+ );
2866
+ return { report, extra };
2862
2867
  }
2863
2868
  async function runTask(ref, agent, opts) {
2864
2869
  const runId = `wtr-${randomBytes(6).toString("hex")}`;
@@ -2962,7 +2967,7 @@ async function runTask(ref, agent, opts) {
2962
2967
  }
2963
2968
  }
2964
2969
  }
2965
- var TaskRun;
2970
+ var TaskRun, describeValue, RESULT_CONTRACT;
2966
2971
  var init_taskRun = __esm({
2967
2972
  "src/worlds/taskRun.ts"() {
2968
2973
  "use strict";
@@ -3033,6 +3038,8 @@ var init_taskRun = __esm({
3033
3038
  Object.assign(this.notes, notes);
3034
3039
  }
3035
3040
  };
3041
+ describeValue = (value) => Array.isArray(value) ? "array" : value === null ? "null" : typeof value;
3042
+ RESULT_CONTRACT = "return a string report, an object {report?: string, ...} or nothing";
3036
3043
  }
3037
3044
  });
3038
3045
 
@@ -3186,16 +3193,21 @@ var init_worldDir = __esm({
3186
3193
  var hub_exports = {};
3187
3194
  __export(hub_exports, {
3188
3195
  DEFAULT_BRANCH: () => DEFAULT_BRANCH,
3196
+ PushSlugConflict: () => PushSlugConflict,
3197
+ archiveMode: () => archiveMode,
3198
+ buildFileManifest: () => buildFileManifest,
3189
3199
  buildSourceTarball: () => buildSourceTarball,
3190
3200
  collectArchiveRelPaths: () => collectArchiveRelPaths,
3191
3201
  computeContentHash: () => computeContentHash,
3192
3202
  createRef: () => createRef,
3203
+ extractBundle: () => extractBundle,
3193
3204
  localTreeState: () => localTreeState,
3194
3205
  propose: () => propose,
3195
3206
  pull: () => pull,
3196
3207
  push: () => push,
3197
3208
  pushSlug: () => pushSlug,
3198
3209
  readLocalMeta: () => readLocalMeta,
3210
+ resolvePushSlug: () => resolvePushSlug,
3199
3211
  snapshotTreeHashes: () => snapshotTreeHashes,
3200
3212
  writeLocalMeta: () => writeLocalMeta
3201
3213
  });
@@ -3217,12 +3229,18 @@ function computeContentHash(dir) {
3217
3229
  return WorldDir.open(dir).contentHash;
3218
3230
  }
3219
3231
  function octal(value, length) {
3220
- return Buffer.from(value.toString(8).padStart(length - 1, "0") + "\0", "ascii");
3232
+ return Buffer.from(
3233
+ value.toString(8).padStart(length - 1, "0") + "\0",
3234
+ "ascii"
3235
+ );
3236
+ }
3237
+ function archiveMode(mode) {
3238
+ return (mode & 73) !== 0 ? EXEC_MODE : FILE_MODE;
3221
3239
  }
3222
- function tarHeader(name, size) {
3240
+ function tarHeader(name, size, mode = FILE_MODE) {
3223
3241
  const header = Buffer.alloc(512);
3224
3242
  header.write(name, 0, 100, "utf-8");
3225
- octal(420, 8).copy(header, 100);
3243
+ octal(mode, 8).copy(header, 100);
3226
3244
  octal(0, 8).copy(header, 108);
3227
3245
  octal(0, 8).copy(header, 116);
3228
3246
  octal(size, 12).copy(header, 124);
@@ -3236,7 +3254,7 @@ function tarHeader(name, size) {
3236
3254
  header.write(sum.toString(8).padStart(6, "0") + "\0 ", 148, "ascii");
3237
3255
  return header;
3238
3256
  }
3239
- function tarMember(name, payload) {
3257
+ function tarMember(name, payload, mode) {
3240
3258
  const parts2 = [];
3241
3259
  const nameBytes = Buffer.byteLength(name, "utf-8");
3242
3260
  if (nameBytes > 100) {
@@ -3250,9 +3268,9 @@ function tarMember(name, payload) {
3250
3268
  parts2.push(lHeader, body);
3251
3269
  const pad2 = body.length % 512 === 0 ? 0 : 512 - body.length % 512;
3252
3270
  if (pad2) parts2.push(Buffer.alloc(pad2));
3253
- parts2.push(tarHeader(name.slice(0, 100), payload.length));
3271
+ parts2.push(tarHeader(name.slice(0, 100), payload.length, mode));
3254
3272
  } else {
3255
- parts2.push(tarHeader(name, payload.length));
3273
+ parts2.push(tarHeader(name, payload.length, mode));
3256
3274
  }
3257
3275
  parts2.push(payload);
3258
3276
  const pad = payload.length % 512 === 0 ? 0 : 512 - payload.length % 512;
@@ -3262,7 +3280,14 @@ function tarMember(name, payload) {
3262
3280
  function buildSourceTarball(dir) {
3263
3281
  const parts2 = [];
3264
3282
  for (const relPath of collectArchiveRelPaths(dir)) {
3265
- parts2.push(...tarMember(relPath, fs3.readFileSync(path3.join(dir, relPath))));
3283
+ const abs = path3.join(dir, relPath);
3284
+ parts2.push(
3285
+ ...tarMember(
3286
+ relPath,
3287
+ fs3.readFileSync(abs),
3288
+ archiveMode(fs3.statSync(abs).mode)
3289
+ )
3290
+ );
3266
3291
  }
3267
3292
  parts2.push(Buffer.alloc(1024));
3268
3293
  return gzipSync(Buffer.concat(parts2), { level: 9 });
@@ -3277,10 +3302,22 @@ function readLocalMeta(dir) {
3277
3302
  }
3278
3303
  }
3279
3304
  function pushSlug(dir, explicit) {
3280
- if (explicit) return explicit;
3305
+ return resolvePushSlug(dir, { explicit }).slug;
3306
+ }
3307
+ function resolvePushSlug(dir, opts = {}) {
3281
3308
  const meta = readLocalMeta(dir);
3282
- if (typeof meta?.slug === "string" && meta.slug) return meta.slug;
3283
- return readPyproject(dir).name ?? path3.basename(path3.resolve(dir));
3309
+ const tracked = typeof meta?.slug === "string" && meta.slug ? meta.slug : null;
3310
+ const declared = Object.entries({ ...opts.declared ?? {}, "pyproject.toml": readPyproject(dir).name }).filter((entry) => typeof entry[1] === "string" && entry[1] !== "").map(([source, slug]) => ({ source, slug }));
3311
+ const base = { tracked, declared, conflict: null };
3312
+ if (opts.explicit) return { ...base, slug: opts.explicit, source: "--slug" };
3313
+ if (tracked) {
3314
+ const minted = (d) => tracked.startsWith(d.slug) && MINTED_SUFFIX.test(tracked.slice(d.slug.length));
3315
+ const conflict = declared.find((d) => d.slug !== tracked && !minted(d)) ?? null;
3316
+ return { ...base, slug: tracked, source: ".gateway metadata", conflict };
3317
+ }
3318
+ const first = declared[0];
3319
+ if (first) return { ...base, slug: first.slug, source: first.source };
3320
+ return { ...base, slug: path3.basename(path3.resolve(dir)), source: "directory name" };
3284
3321
  }
3285
3322
  function writeLocalMeta(dir, meta) {
3286
3323
  fs3.mkdirSync(path3.join(dir, ".gateway"), { recursive: true });
@@ -3319,7 +3356,9 @@ function readPyproject(dir) {
3319
3356
  function readWorldContractVersion(dir) {
3320
3357
  const world = WorldDir.open(dir);
3321
3358
  try {
3322
- const parsed = JSON.parse(world.text(world.worldPath("schema/world.json")) ?? "");
3359
+ const parsed = JSON.parse(
3360
+ world.text(world.worldPath("schema/world.json")) ?? ""
3361
+ );
3323
3362
  const pkg = parsed["x-gateway"]?.package;
3324
3363
  if (pkg?.version) return { name: pkg.id, version: pkg.version };
3325
3364
  } catch {
@@ -3327,28 +3366,15 @@ function readWorldContractVersion(dir) {
3327
3366
  return {};
3328
3367
  }
3329
3368
  function buildFileManifest(dir) {
3330
- const entries = [];
3331
- const walk = (rel) => {
3332
- const abs = rel ? path3.join(dir, rel) : dir;
3333
- for (const entry of fs3.readdirSync(abs, { withFileTypes: true }).sort((a, b) => a.name.localeCompare(b.name))) {
3334
- const childRel = rel ? `${rel}/${entry.name}` : entry.name;
3335
- if (entry.isDirectory()) {
3336
- if (!SKIP_DIRS.has(entry.name) && !entry.name.endsWith(".egg-info")) {
3337
- walk(childRel);
3338
- }
3339
- } else if (entry.isFile()) {
3340
- const payload = fs3.readFileSync(path3.join(dir, childRel));
3341
- entries.push({
3342
- path: childRel,
3343
- isDirectory: false,
3344
- size: payload.length,
3345
- sha256: createHash4("sha256").update(payload).digest("hex")
3346
- });
3347
- }
3348
- }
3349
- };
3350
- walk("");
3351
- return entries;
3369
+ return collectArchiveRelPaths(dir).map((relPath) => {
3370
+ const payload = fs3.readFileSync(path3.join(dir, relPath));
3371
+ return {
3372
+ path: relPath,
3373
+ isDirectory: false,
3374
+ size: payload.length,
3375
+ sha256: createHash4("sha256").update(payload).digest("hex")
3376
+ };
3377
+ });
3352
3378
  }
3353
3379
  async function putObject(url, data, shaB64) {
3354
3380
  const resp = await fetch(url, {
@@ -3360,22 +3386,30 @@ async function putObject(url, data, shaB64) {
3360
3386
  body: new Uint8Array(data)
3361
3387
  });
3362
3388
  if (!resp.ok) {
3363
- throw new Error(`object PUT -> ${resp.status}: ${(await resp.text()).slice(0, 300)}`);
3389
+ throw new Error(
3390
+ `object PUT -> ${resp.status}: ${(await resp.text()).slice(0, 300)}`
3391
+ );
3364
3392
  }
3365
3393
  }
3366
3394
  async function push(dir, opts = {}) {
3367
3395
  const options = opts.options ?? {};
3368
- if (!fs3.statSync(dir).isDirectory()) throw new Error(`Not a directory: ${dir}`);
3396
+ if (!fs3.statSync(dir).isDirectory())
3397
+ throw new Error(`Not a directory: ${dir}`);
3369
3398
  const localMeta = readLocalMeta(dir) ?? {};
3370
3399
  const branch = opts.branch ?? localMeta.branch ?? DEFAULT_BRANCH;
3371
3400
  const baseVersionId = opts.baseVersionId ?? localMeta.versionId ?? null;
3401
+ const fileManifest = buildFileManifest(dir);
3402
+ if (fileManifest.length === 0)
3403
+ throw new Error(
3404
+ `Nothing to push: ${dir} has no files the archive rules keep (a world root marker, README.md, pyproject.toml, *.py, or any file below a subdirectory).`
3405
+ );
3372
3406
  const contentHash = computeContentHash(dir);
3373
3407
  const pyproject = readPyproject(dir);
3374
3408
  const contractVersion = pyproject.version ? void 0 : readWorldContractVersion(dir).version;
3375
3409
  if (contractVersion) pyproject.version = contractVersion;
3376
3410
  const slug = opts.slug ?? localMeta.slug ?? pyproject.name ?? path3.basename(path3.resolve(dir));
3377
3411
  const metadata = {
3378
- name: opts.name ?? pyproject.name ?? slug,
3412
+ ...opts.name !== void 0 ? { name: opts.name } : {},
3379
3413
  ...opts.description !== void 0 ? { description: opts.description } : {},
3380
3414
  ...opts.tags !== void 0 ? { tags: opts.tags } : {},
3381
3415
  ...opts.visibility ? { visibility: opts.visibility } : {}
@@ -3395,7 +3429,7 @@ async function push(dir, opts = {}) {
3395
3429
  bundleSizeBytes: tarball.length,
3396
3430
  ...pyproject.version ? { semanticVersion: pyproject.version } : {},
3397
3431
  pyprojectMeta: pyproject,
3398
- fileManifest: buildFileManifest(dir),
3432
+ fileManifest,
3399
3433
  branch,
3400
3434
  baseVersionId,
3401
3435
  ...opts.force ? { force: true } : {},
@@ -3403,12 +3437,18 @@ async function push(dir, opts = {}) {
3403
3437
  ...opts.author ? { author: opts.author } : {},
3404
3438
  ...opts.imageRef ? { imageRef: opts.imageRef } : {}
3405
3439
  });
3406
- if (version.uploadUrl) await putObject(version.uploadUrl, tarball, bundleSha256);
3440
+ if (version.uploadUrl)
3441
+ await putObject(version.uploadUrl, tarball, bundleSha256);
3407
3442
  const final = await apiRequest(
3408
3443
  options,
3409
3444
  "POST",
3410
3445
  `/api/public/benchmark-containers/versions/${version.versionId}/finalize`,
3411
- { branch, baseVersionId, ...opts.force ? { force: true } : {}, ...metadata }
3446
+ {
3447
+ branch,
3448
+ baseVersionId,
3449
+ ...opts.force ? { force: true } : {},
3450
+ ...metadata
3451
+ }
3412
3452
  );
3413
3453
  writeLocalMeta(dir, {
3414
3454
  ...localMeta,
@@ -3441,7 +3481,14 @@ function extractBundle(bundle, dir) {
3441
3481
  offset += 512;
3442
3482
  if (header.every((b) => b === 0)) break;
3443
3483
  const rawName = header.subarray(0, 100).toString("utf-8").replace(/\0.*$/, "");
3444
- const size = parseInt(header.subarray(124, 136).toString("ascii").replace(/\0.*$/, "").trim(), 8) || 0;
3484
+ const size = parseInt(
3485
+ header.subarray(124, 136).toString("ascii").replace(/\0.*$/, "").trim(),
3486
+ 8
3487
+ ) || 0;
3488
+ const mode = parseInt(
3489
+ header.subarray(100, 108).toString("ascii").replace(/\0.*$/, "").trim(),
3490
+ 8
3491
+ ) || FILE_MODE;
3445
3492
  const typeflag = header.subarray(156, 157).toString("ascii");
3446
3493
  const body = tar.subarray(offset, offset + size);
3447
3494
  offset += size + (size % 512 === 0 ? 0 : 512 - size % 512);
@@ -3455,7 +3502,8 @@ function extractBundle(bundle, dir) {
3455
3502
  if (name.startsWith("/") || name.split("/").includes("..")) continue;
3456
3503
  const target = path3.join(dir, name);
3457
3504
  fs3.mkdirSync(path3.dirname(target), { recursive: true });
3458
- fs3.writeFileSync(target, body);
3505
+ fs3.writeFileSync(target, body, { mode: archiveMode(mode) });
3506
+ fs3.chmodSync(target, archiveMode(mode));
3459
3507
  written++;
3460
3508
  }
3461
3509
  return written;
@@ -3502,13 +3550,17 @@ async function pull(slugRef, target, options = {}) {
3502
3550
  async function propose(dir, opts) {
3503
3551
  const meta = readLocalMeta(dir);
3504
3552
  if (!meta?.slug || !meta.baseFiles) {
3505
- throw new Error("This dir has no pull/push base \u2014 run pull first, then edit, then propose.");
3553
+ throw new Error(
3554
+ "This dir has no pull/push base \u2014 run pull first, then edit, then propose."
3555
+ );
3506
3556
  }
3507
3557
  const state2 = localTreeState(dir);
3508
- if (state2.clean) throw new Error("Nothing to propose \u2014 the tree matches its base.");
3558
+ if (state2.clean)
3559
+ throw new Error("Nothing to propose \u2014 the tree matches its base.");
3509
3560
  const changes = state2.dirty.map((relPath) => {
3510
3561
  const abs = path3.join(dir, relPath);
3511
- if (!fs3.existsSync(abs)) return { path: relPath, action: "delete" };
3562
+ if (!fs3.existsSync(abs))
3563
+ return { path: relPath, action: "delete" };
3512
3564
  return {
3513
3565
  path: relPath,
3514
3566
  action: "write",
@@ -3538,7 +3590,7 @@ async function createRef(slug, name, kind, versionId, options = {}) {
3538
3590
  ...versionId ? { versionId } : {}
3539
3591
  });
3540
3592
  }
3541
- var DEFAULT_BRANCH, META_RELPATH, SKIP_DIRS, sha256b64;
3593
+ var DEFAULT_BRANCH, META_RELPATH, FILE_MODE, EXEC_MODE, MINTED_SUFFIX, PushSlugConflict, sha256b64;
3542
3594
  var init_hub = __esm({
3543
3595
  "src/worlds/hub.ts"() {
3544
3596
  "use strict";
@@ -3546,16 +3598,20 @@ var init_hub = __esm({
3546
3598
  init_worldDir();
3547
3599
  DEFAULT_BRANCH = "main";
3548
3600
  META_RELPATH = path3.join(".gateway", ".env-metadata.json");
3549
- SKIP_DIRS = /* @__PURE__ */ new Set([
3550
- ".git",
3551
- "__pycache__",
3552
- "node_modules",
3553
- ".venv",
3554
- ".mypy_cache",
3555
- "dist",
3556
- "build",
3557
- "outputs"
3558
- ]);
3601
+ FILE_MODE = 420;
3602
+ EXEC_MODE = 493;
3603
+ MINTED_SUFFIX = /^-\d+$/;
3604
+ PushSlugConflict = class extends Error {
3605
+ constructor(dir, tracked, declared) {
3606
+ super(
3607
+ `${dir} tracks slug \`${tracked}\` (${META_RELPATH}, from an earlier push) but its ${declared.source} says \`${declared.slug}\`. Nothing was pushed. Pass --slug ${declared.slug} to push there (and retrack the dir), --slug ${tracked} to keep pushing to \`${tracked}\`, or delete ${META_RELPATH} to forget the earlier push.`
3608
+ );
3609
+ this.dir = dir;
3610
+ this.tracked = tracked;
3611
+ this.declared = declared;
3612
+ this.name = "PushSlugConflict";
3613
+ }
3614
+ };
3559
3615
  sha256b64 = (data) => createHash4("sha256").update(data).digest("base64");
3560
3616
  }
3561
3617
  });
@@ -4130,8 +4186,8 @@ function hashForm(slug, plaintext) {
4130
4186
  }
4131
4187
  function preserveForm(slug, plaintext) {
4132
4188
  const kind = typeof plaintext === "string" ? "str" : isInt(plaintext) ? "int" : "float";
4133
- const shaped = shapeText(slug, pyText(plaintext), kind);
4134
- return kind === "str" ? shaped : Number(shaped);
4189
+ const shaped2 = shapeText(slug, pyText(plaintext), kind);
4190
+ return kind === "str" ? shaped2 : Number(shaped2);
4135
4191
  }
4136
4192
  function shapeText(slug, text2, kind) {
4137
4193
  const seed = Buffer.from(`${slug}:${text2}`, "utf8");
@@ -4267,11 +4323,20 @@ var init_router = __esm({
4267
4323
  import * as fs4 from "fs";
4268
4324
  import * as os from "os";
4269
4325
  import * as path4 from "path";
4326
+ function transportDetail(error, timeoutMs) {
4327
+ if (error instanceof Error && error.name === "AbortError") return `timed out after ${Math.round(timeoutMs / 1e3)}s`;
4328
+ const cause = error instanceof Error && error.cause instanceof Error ? error.cause : void 0;
4329
+ const code = cause && "code" in cause && typeof cause.code === "string" ? `${cause.code}: ` : "";
4330
+ const message = cause?.message ?? (error instanceof Error ? error.message : String(error));
4331
+ return `${code}${message}`;
4332
+ }
4270
4333
  async function api(creds, method, route, body, init3 = {}) {
4271
4334
  const controller = new AbortController();
4272
- const timer = setTimeout(() => controller.abort(), init3.timeoutMs ?? 12e4);
4335
+ const timeoutMs = init3.timeoutMs ?? 12e4;
4336
+ const timer = setTimeout(() => controller.abort(), timeoutMs);
4337
+ let res;
4273
4338
  try {
4274
- const res = await fetch(`${creds.host}${route}`, {
4339
+ res = await fetch(`${creds.host}${route}`, {
4275
4340
  method,
4276
4341
  headers: {
4277
4342
  "content-type": "application/json",
@@ -4281,6 +4346,11 @@ async function api(creds, method, route, body, init3 = {}) {
4281
4346
  ...body === void 0 ? {} : { body: JSON.stringify(body) },
4282
4347
  signal: controller.signal
4283
4348
  });
4349
+ } catch (error) {
4350
+ clearTimeout(timer);
4351
+ throw new UnreachableError(creds.host, method, route, transportDetail(error, timeoutMs));
4352
+ }
4353
+ try {
4284
4354
  const text2 = await res.text();
4285
4355
  if (!res.ok) throw new ApiError(res.status, method, route, text2);
4286
4356
  return text2 ? JSON.parse(text2) : {};
@@ -4288,7 +4358,7 @@ async function api(creds, method, route, body, init3 = {}) {
4288
4358
  clearTimeout(timer);
4289
4359
  }
4290
4360
  }
4291
- var ApiError;
4361
+ var ApiError, UnreachableError;
4292
4362
  var init_config = __esm({
4293
4363
  "src/cli/config.ts"() {
4294
4364
  "use strict";
@@ -4302,6 +4372,15 @@ var init_config = __esm({
4302
4372
  this.text = text2;
4303
4373
  }
4304
4374
  };
4375
+ UnreachableError = class extends CliError {
4376
+ constructor(host, method, route, detail) {
4377
+ super(`${method} ${route}: no answer from ${host} (${detail}). Check the host and the network, then retry.`, 1);
4378
+ this.host = host;
4379
+ this.method = method;
4380
+ this.route = route;
4381
+ this.detail = detail;
4382
+ }
4383
+ };
4305
4384
  }
4306
4385
  });
4307
4386
 
@@ -4517,7 +4596,7 @@ function readWorldFiles(dir, opts = {}) {
4517
4596
  for (const entry of entries) {
4518
4597
  const childRel = rel ? `${rel}/${entry.name}` : entry.name;
4519
4598
  if (entry.isDirectory()) {
4520
- if (!SKIP_DIRS2.has(entry.name)) walk(childRel);
4599
+ if (!SKIP_DIRS.has(entry.name)) walk(childRel);
4521
4600
  } else if (entry.isFile()) {
4522
4601
  if (!opts.buildOutputs && isBuildOutput(childRel)) continue;
4523
4602
  out.push({
@@ -4560,7 +4639,7 @@ function pruneEmptyDirs(root) {
4560
4639
  for (const entry of fs6.readdirSync(abs, { withFileTypes: true })) {
4561
4640
  const child = path6.join(abs, entry.name);
4562
4641
  if (entry.isDirectory()) {
4563
- if (SKIP_DIRS2.has(entry.name)) {
4642
+ if (SKIP_DIRS.has(entry.name)) {
4564
4643
  empty = false;
4565
4644
  continue;
4566
4645
  }
@@ -4628,13 +4707,13 @@ async function runtime(creds, request, opts = {}) {
4628
4707
  clearTimeout(timer);
4629
4708
  }
4630
4709
  }
4631
- var SKIP_DIRS2, BUILD_OUTPUT, BridgeRejected;
4710
+ var SKIP_DIRS, BUILD_OUTPUT, BridgeRejected;
4632
4711
  var init_client = __esm({
4633
4712
  "src/cli/runtime/client.ts"() {
4634
4713
  "use strict";
4635
4714
  init_router();
4636
4715
  init_local();
4637
- SKIP_DIRS2 = /* @__PURE__ */ new Set(["__pycache__", ".git", "node_modules", ".gateway"]);
4716
+ SKIP_DIRS = /* @__PURE__ */ new Set(["__pycache__", ".git", "node_modules", ".gateway"]);
4638
4717
  BUILD_OUTPUT = /(^|\/)state\.(sqlite|json)$/;
4639
4718
  BridgeRejected = class extends CliError {
4640
4719
  constructor(detail) {
@@ -5054,7 +5133,12 @@ var init_batches = __esm({
5054
5133
  "use strict";
5055
5134
  init_config();
5056
5135
  init_router();
5057
- TERMINAL_STATES = /* @__PURE__ */ new Set(["applied", "refused", "published", "failed"]);
5136
+ TERMINAL_STATES = /* @__PURE__ */ new Set([
5137
+ "applied",
5138
+ "refused",
5139
+ "published",
5140
+ "failed"
5141
+ ]);
5058
5142
  sleepMs = (ms) => new Promise((resolve10) => setTimeout(resolve10, ms));
5059
5143
  WorldDataApi = class {
5060
5144
  constructor(creds, slug, sleep3 = sleepMs) {
@@ -5068,22 +5152,61 @@ var init_batches = __esm({
5068
5152
  return api(this.creds, "POST", `${this.base}/batches`, body);
5069
5153
  }
5070
5154
  register(batchId, chunk) {
5071
- return api(this.creds, "POST", `${this.base}/batches/${batchId}/chunks`, {
5155
+ return api(
5156
+ this.creds,
5157
+ "POST",
5158
+ `${this.base}/batches/${batchId}/chunks`,
5159
+ {
5160
+ ordinal: chunk.ordinal,
5161
+ digest: chunk.digest,
5162
+ bytes: chunk.bytes,
5163
+ rows: chunk.rows,
5164
+ ...chunk.entity ? { entity: chunk.entity } : {}
5165
+ }
5166
+ );
5167
+ }
5168
+ /**
5169
+ * Stage a project-drive rows file as one chunk, on the platform: the server
5170
+ * streams it out of drive storage into chunk storage and answers with the
5171
+ * digest and gzipped size it derived. No bytes pass through this process.
5172
+ */
5173
+ async stageDrive(batchId, chunk) {
5174
+ const staged = await api(this.creds, "POST", `${this.base}/batches/${batchId}/chunks`, {
5072
5175
  ordinal: chunk.ordinal,
5073
- digest: chunk.digest,
5074
- bytes: chunk.bytes,
5075
- rows: chunk.rows,
5176
+ drive: chunk.path,
5076
5177
  ...chunk.entity ? { entity: chunk.entity } : {}
5077
5178
  });
5179
+ if (!staged.uploaded || !staged.digest || staged.bytes === void 0 || staged.rows === void 0)
5180
+ throw new CliError(
5181
+ `the server staged drive:${chunk.path} as chunk ${chunk.ordinal} without its digest, size and rows`,
5182
+ 1
5183
+ );
5184
+ return {
5185
+ ordinal: chunk.ordinal,
5186
+ digest: staged.digest,
5187
+ bytes: staged.bytes,
5188
+ rows: staged.rows,
5189
+ entity: chunk.entity,
5190
+ chunkId: staged.chunkId,
5191
+ uploaded: true
5192
+ };
5078
5193
  }
5079
5194
  markUploaded(batchId, chunkId) {
5080
- return api(this.creds, "POST", `${this.base}/batches/${batchId}/chunks/${chunkId}/uploaded`);
5195
+ return api(
5196
+ this.creds,
5197
+ "POST",
5198
+ `${this.base}/batches/${batchId}/chunks/${chunkId}/uploaded`
5199
+ );
5081
5200
  }
5082
5201
  complete(batchId) {
5083
5202
  return api(this.creds, "POST", `${this.base}/batches/${batchId}/complete`);
5084
5203
  }
5085
5204
  get(batchId) {
5086
- return api(this.creds, "GET", `${this.base}/batches/${batchId}`);
5205
+ return api(
5206
+ this.creds,
5207
+ "GET",
5208
+ `${this.base}/batches/${batchId}`
5209
+ );
5087
5210
  }
5088
5211
  list(limit, cursor) {
5089
5212
  const params = new URLSearchParams();
@@ -5093,7 +5216,12 @@ var init_batches = __esm({
5093
5216
  return api(this.creds, "GET", `${this.base}/batches${q ? `?${q}` : ""}`);
5094
5217
  }
5095
5218
  publish(message) {
5096
- return api(this.creds, "POST", `${this.base}/publish`, message ? { message } : {});
5219
+ return api(
5220
+ this.creds,
5221
+ "POST",
5222
+ `${this.base}/publish`,
5223
+ message ? { message } : {}
5224
+ );
5097
5225
  }
5098
5226
  /**
5099
5227
  * PUT the gzipped chunk to its presigned URL with exactly the headers the
@@ -5105,11 +5233,23 @@ var init_batches = __esm({
5105
5233
  const delays = [500, 1500, 4e3];
5106
5234
  for (let attempt = 0; ; attempt++) {
5107
5235
  try {
5108
- const res = await fetch(uploadUrl, { method: "PUT", body: new Uint8Array(gz), headers });
5236
+ const res = await fetch(uploadUrl, {
5237
+ method: "PUT",
5238
+ body: new Uint8Array(gz),
5239
+ headers
5240
+ });
5109
5241
  if (res.ok) return;
5110
- if (res.status < 500 || attempt >= delays.length) throw new CliError(`chunk upload -> ${res.status}: ${(await res.text()).slice(0, 300)}`, 1);
5242
+ if (res.status < 500 || attempt >= delays.length)
5243
+ throw new CliError(
5244
+ `chunk upload -> ${res.status}: ${(await res.text()).slice(0, 300)}`,
5245
+ 1
5246
+ );
5111
5247
  } catch (error) {
5112
- if (error instanceof CliError || attempt >= delays.length) throw error instanceof CliError ? error : new CliError(`chunk upload failed: ${error.message}`, 1);
5248
+ if (error instanceof CliError || attempt >= delays.length)
5249
+ throw error instanceof CliError ? error : new CliError(
5250
+ `chunk upload failed: ${error.message}`,
5251
+ 1
5252
+ );
5113
5253
  }
5114
5254
  await this.sleep(delays[attempt]);
5115
5255
  }
@@ -5118,11 +5258,23 @@ var init_batches = __esm({
5118
5258
  async upload(batchId, chunk) {
5119
5259
  const registered = await this.register(batchId, chunk);
5120
5260
  if (!registered.uploaded) {
5121
- if (!registered.uploadUrl) throw new CliError(`the server registered chunk ${chunk.ordinal} without an upload URL`, 1);
5261
+ if (!registered.uploadUrl)
5262
+ throw new CliError(
5263
+ `the server registered chunk ${chunk.ordinal} without an upload URL`,
5264
+ 1
5265
+ );
5122
5266
  await this.put(registered.uploadUrl, chunk.gz, registered.uploadHeaders);
5123
5267
  await this.markUploaded(batchId, registered.chunkId);
5124
5268
  }
5125
- return { ordinal: chunk.ordinal, digest: chunk.digest, bytes: chunk.bytes, rows: chunk.rows, entity: chunk.entity, chunkId: registered.chunkId, uploaded: true };
5269
+ return {
5270
+ ordinal: chunk.ordinal,
5271
+ digest: chunk.digest,
5272
+ bytes: chunk.bytes,
5273
+ rows: chunk.rows,
5274
+ entity: chunk.entity,
5275
+ chunkId: registered.chunkId,
5276
+ uploaded: true
5277
+ };
5126
5278
  }
5127
5279
  };
5128
5280
  }
@@ -5138,14 +5290,20 @@ function chunkLine(row, declared) {
5138
5290
  tagged.set("row", row.row);
5139
5291
  return dumps(tagged) + "\n";
5140
5292
  }
5141
- async function* buildChunks(rows, plan) {
5293
+ async function* buildChunks(rows, plan, ordinalStart = 0) {
5142
5294
  let lines = [];
5143
5295
  let rawBytes = 0;
5144
- let ordinal = 0;
5296
+ let ordinal = ordinalStart;
5145
5297
  let seen = 0;
5146
5298
  const flush2 = () => {
5147
5299
  const raw = Buffer.concat(lines);
5148
- const built = finishChunk(ordinal++, raw, lines.length, plan.entity, seen - lines.length);
5300
+ const built = finishChunk(
5301
+ ordinal++,
5302
+ raw,
5303
+ lines.length,
5304
+ plan.entity,
5305
+ seen - lines.length
5306
+ );
5149
5307
  lines = [];
5150
5308
  rawBytes = 0;
5151
5309
  return built;
@@ -5177,7 +5335,18 @@ function finishChunk(ordinal, raw, rows, entity, firstRow = 0) {
5177
5335
  function gzipDeterministic(raw, opts = {}) {
5178
5336
  const level = opts.level ?? GZIP_LEVEL;
5179
5337
  const name = opts.name ? Buffer.concat([Buffer.from(opts.name, "latin1"), Buffer.from([0])]) : Buffer.alloc(0);
5180
- const header = Buffer.from([31, 139, 8, opts.name ? 8 : 0, 0, 0, 0, 0, level === 9 ? 2 : level === 1 ? 4 : 0, 255]);
5338
+ const header = Buffer.from([
5339
+ 31,
5340
+ 139,
5341
+ 8,
5342
+ opts.name ? 8 : 0,
5343
+ 0,
5344
+ 0,
5345
+ 0,
5346
+ 0,
5347
+ level === 9 ? 2 : level === 1 ? 4 : 0,
5348
+ 255
5349
+ ]);
5181
5350
  const body = deflateRawSync(raw, { level });
5182
5351
  const trailer = Buffer.alloc(8);
5183
5352
  trailer.writeUInt32LE(crc32(raw), 0);
@@ -5194,7 +5363,8 @@ function crc32(data) {
5194
5363
  }
5195
5364
  }
5196
5365
  let crc = 4294967295;
5197
- for (let i = 0; i < data.length; i++) crc = table[(crc ^ data[i]) & 255] ^ crc >>> 8;
5366
+ for (let i = 0; i < data.length; i++)
5367
+ crc = table[(crc ^ data[i]) & 255] ^ crc >>> 8;
5198
5368
  return (crc ^ 4294967295) >>> 0;
5199
5369
  }
5200
5370
  var DEFAULT_CHUNK_BYTES, GZIP_LEVEL, chunkName, table;
@@ -5493,6 +5663,58 @@ var init_ingest = __esm({
5493
5663
  }
5494
5664
  });
5495
5665
 
5666
+ // src/worlds/sandbox.ts
5667
+ function parseSlugRef(slugRef) {
5668
+ const at = slugRef.indexOf("@");
5669
+ if (at === -1) return { slug: slugRef };
5670
+ return { slug: slugRef.slice(0, at), ref: slugRef.slice(at + 1) };
5671
+ }
5672
+ var sid, WorldSandboxClient;
5673
+ var init_sandbox = __esm({
5674
+ "src/worlds/sandbox.ts"() {
5675
+ "use strict";
5676
+ init_worlds();
5677
+ sid = encodeURIComponent;
5678
+ WorldSandboxClient = class {
5679
+ constructor(options = {}) {
5680
+ this.options = options;
5681
+ }
5682
+ open(target) {
5683
+ return apiRequest(this.options, "POST", "/api/public/benchmark-containers/sandboxes", target);
5684
+ }
5685
+ status(sandboxId) {
5686
+ return apiRequest(this.options, "GET", `/api/public/benchmark-containers/sandboxes/${sid(sandboxId)}`);
5687
+ }
5688
+ async read(sandboxId, filePath) {
5689
+ const res = await apiRequest(
5690
+ this.options,
5691
+ "GET",
5692
+ `/api/public/benchmark-containers/sandboxes/${sid(sandboxId)}/file?path=${encodeURIComponent(filePath)}`
5693
+ );
5694
+ return { path: res.path, size: res.size, bytes: Buffer.from(res.contentBase64, "base64") };
5695
+ }
5696
+ write(sandboxId, filePath, bytes) {
5697
+ return apiRequest(this.options, "PUT", `/api/public/benchmark-containers/sandboxes/${sid(sandboxId)}/file`, {
5698
+ path: filePath,
5699
+ contentBase64: bytes.toString("base64")
5700
+ });
5701
+ }
5702
+ exec(sandboxId, input) {
5703
+ return apiRequest(this.options, "POST", `/api/public/benchmark-containers/sandboxes/${sid(sandboxId)}/exec`, input);
5704
+ }
5705
+ check(sandboxId) {
5706
+ return apiRequest(this.options, "POST", `/api/public/benchmark-containers/sandboxes/${sid(sandboxId)}/check`, {});
5707
+ }
5708
+ commit(sandboxId, input) {
5709
+ return apiRequest(this.options, "POST", `/api/public/benchmark-containers/sandboxes/${sid(sandboxId)}/commit`, input);
5710
+ }
5711
+ close(sandboxId) {
5712
+ return apiRequest(this.options, "DELETE", `/api/public/benchmark-containers/sandboxes/${sid(sandboxId)}`);
5713
+ }
5714
+ };
5715
+ }
5716
+ });
5717
+
5496
5718
  // src/worlds/index.ts
5497
5719
  var worlds_exports = {};
5498
5720
  __export(worlds_exports, {
@@ -5505,6 +5727,7 @@ __export(worlds_exports, {
5505
5727
  EVENT_FLUSH_INTERVAL_MS: () => EVENT_FLUSH_INTERVAL_MS,
5506
5728
  EVENT_MAX_RETRIES: () => EVENT_MAX_RETRIES,
5507
5729
  GatewayEvalsClient: () => GatewayEvalsClient,
5730
+ PushSlugConflict: () => PushSlugConflict,
5508
5731
  STRIP_PREFIX: () => STRIP_PREFIX,
5509
5732
  SURFACE_KINDS: () => SURFACE_KINDS,
5510
5733
  TRANSFORMS: () => TRANSFORMS,
@@ -5512,6 +5735,7 @@ __export(worlds_exports, {
5512
5735
  TaskSessions: () => TaskSessions,
5513
5736
  WHITESPACE: () => WHITESPACE,
5514
5737
  WorldBrowser: () => WorldBrowser,
5738
+ WorldSandboxClient: () => WorldSandboxClient,
5515
5739
  WorldSession: () => WorldSession,
5516
5740
  WorldSessionCallError: () => WorldSessionCallError,
5517
5741
  WorldSessionTimeout: () => WorldSessionTimeout,
@@ -5521,9 +5745,11 @@ __export(worlds_exports, {
5521
5745
  aggregateTaskGrade: () => aggregateTaskGrade,
5522
5746
  apiRequest: () => apiRequest,
5523
5747
  applyTransforms: () => applyTransforms,
5748
+ archiveMode: () => archiveMode,
5524
5749
  attachManifest: () => attachManifest,
5525
5750
  attachSession: () => attachSession,
5526
5751
  attachTask: () => attachTask,
5752
+ buildFileManifest: () => buildFileManifest,
5527
5753
  buildSourceTarball: () => buildSourceTarball,
5528
5754
  captureToolCalls: () => captureToolCalls,
5529
5755
  collectArchiveRelPaths: () => collectArchiveRelPaths,
@@ -5535,6 +5761,7 @@ __export(worlds_exports, {
5535
5761
  deleteTask: () => deleteTask,
5536
5762
  describeWorld: () => describeWorld,
5537
5763
  detectProvenance: () => detectProvenance,
5764
+ extractBundle: () => extractBundle,
5538
5765
  getRun: () => getRun,
5539
5766
  getTask: () => getTask,
5540
5767
  hashForm: () => hashForm,
@@ -5555,6 +5782,8 @@ __export(worlds_exports, {
5555
5782
  openSession: () => openSession,
5556
5783
  openTask: () => openTask,
5557
5784
  openWorld: () => openWorld,
5785
+ openWorldVersion: () => openWorldVersion,
5786
+ parseSlugRef: () => parseSlugRef,
5558
5787
  parseToolCallRecord: () => parseToolCallRecord,
5559
5788
  parseTransform: () => parseTransform,
5560
5789
  parseWorldTaskRefs: () => parseWorldTaskRefs,
@@ -5571,6 +5800,7 @@ __export(worlds_exports, {
5571
5800
  redactActionArgs: () => redactActionArgs,
5572
5801
  redactionOf: () => redactionOf,
5573
5802
  resolveBrowserMode: () => resolveBrowserMode,
5803
+ resolvePushSlug: () => resolvePushSlug,
5574
5804
  roundForm: () => roundForm,
5575
5805
  runSessions: () => runSessions,
5576
5806
  runTask: () => runTask,
@@ -5745,9 +5975,21 @@ async function openWorld(slugRef, options = {}) {
5745
5975
  const at = slugRef.indexOf("@");
5746
5976
  const slug = at === -1 ? slugRef : slugRef.slice(0, at);
5747
5977
  const ref = at === -1 ? null : slugRef.slice(at + 1);
5978
+ return resolveWorld(slugRef, slug, ref, ref ? { ref } : {}, options);
5979
+ }
5980
+ async function openWorldVersion(slug, versionId, options = {}) {
5981
+ return resolveWorld(
5982
+ `${slug}@${versionId}`,
5983
+ slug,
5984
+ null,
5985
+ { versionId },
5986
+ options
5987
+ );
5988
+ }
5989
+ async function resolveWorld(slugRef, slug, ref, pin, options) {
5748
5990
  const version = await apiRequest(options, "POST", "/api/public/benchmark-containers/resolve-version", {
5749
5991
  slug,
5750
- ...ref ? { ref } : {}
5992
+ ...pin
5751
5993
  });
5752
5994
  const world = new WorldSet(
5753
5995
  slugRef,
@@ -5786,6 +6028,7 @@ var init_worlds = __esm({
5786
6028
  init_query();
5787
6029
  init_migrate();
5788
6030
  init_ingest();
6031
+ init_sandbox();
5789
6032
  ApiError2 = class extends Error {
5790
6033
  constructor(status, method, path14, body) {
5791
6034
  super(`${method} ${path14} -> ${status}: ${body}`);
@@ -8536,6 +8779,7 @@ var hooks_exports = {};
8536
8779
  __export(hooks_exports, {
8537
8780
  AliasHandler: () => AliasHandler,
8538
8781
  AliasMap: () => AliasMap,
8782
+ AuditReport: () => AuditReport,
8539
8783
  CONTEXT_KEY: () => CONTEXT_KEY,
8540
8784
  CallableTool: () => CallableTool,
8541
8785
  CommandHandler: () => CommandHandler,
@@ -8543,6 +8787,8 @@ __export(hooks_exports, {
8543
8787
  DenyHandler: () => DenyHandler,
8544
8788
  EVENTS: () => EVENTS,
8545
8789
  EVENT_ALIASES: () => EVENT_ALIASES,
8790
+ FieldSource: () => FieldSource,
8791
+ FinderSource: () => FinderSource,
8546
8792
  FunctionHandler: () => FunctionHandler,
8547
8793
  HANDLER_TYPES: () => HANDLER_TYPES,
8548
8794
  HookConfigError: () => HookConfigError,
@@ -8554,13 +8800,18 @@ __export(hooks_exports, {
8554
8800
  HttpTool: () => HttpTool,
8555
8801
  INBOUND_KINDS: () => INBOUND_KINDS,
8556
8802
  INPUT_TYPES: () => INPUT_TYPES,
8803
+ Identifier: () => Identifier,
8804
+ IdentifierCensus: () => IdentifierCensus,
8805
+ IdentifierSource: () => IdentifierSource,
8557
8806
  KINDS: () => KINDS,
8807
+ LegendSource: () => LegendSource,
8558
8808
  LiveToolError: () => LiveToolError,
8559
8809
  LiveTools: () => LiveTools,
8560
8810
  PARSE_MODES: () => PARSE_MODES,
8561
8811
  RecordHandler: () => RecordHandler,
8562
8812
  Recorder: () => Recorder,
8563
8813
  RedactHandler: () => RedactHandler,
8814
+ RedactionAudit: () => RedactionAudit,
8564
8815
  Replay: () => Replay,
8565
8816
  TOOL_KINDS: () => TOOL_KINDS,
8566
8817
  applyLimit: () => applyLimit,
@@ -8615,6 +8866,49 @@ __export(hooks_exports, {
8615
8866
  withDefaults: () => withDefaults
8616
8867
  });
8617
8868
 
8869
+ // src/hooks/caseSwap.ts
8870
+ var CASE_SWAP_MIN_CHARS = 4;
8871
+ var standingAlone = /* @__PURE__ */ new Map();
8872
+ function standingAlonePattern(needle) {
8873
+ let pattern = standingAlone.get(needle);
8874
+ if (pattern === void 0) {
8875
+ const escaped = needle.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
8876
+ pattern = new RegExp(`(?<![A-Za-z0-9])${escaped}(?![A-Za-z0-9])`, "gi");
8877
+ standingAlone.set(needle, pattern);
8878
+ }
8879
+ return pattern;
8880
+ }
8881
+ var WORD = /[A-Za-z0-9]+/g;
8882
+ function shapedWord(word, seen) {
8883
+ const hasLetter = seen.toLowerCase() !== seen.toUpperCase();
8884
+ if (hasLetter && seen === seen.toUpperCase()) return word.toUpperCase();
8885
+ if (hasLetter && seen === seen.toLowerCase()) return word.toLowerCase();
8886
+ const first = seen.slice(0, 1);
8887
+ if (first !== first.toLowerCase())
8888
+ return word.slice(0, 1).toUpperCase() + word.slice(1);
8889
+ return word;
8890
+ }
8891
+ function shaped(replacement, seen) {
8892
+ const seenWords = seen.match(WORD) ?? [];
8893
+ if (seenWords.length !== (replacement.match(WORD) ?? []).length)
8894
+ return shapedWord(replacement, seen);
8895
+ let index2 = 0;
8896
+ return replacement.replace(
8897
+ WORD,
8898
+ (word) => shapedWord(word, seenWords[index2++])
8899
+ );
8900
+ }
8901
+ function swapValue(text2, needle, replacement) {
8902
+ if (!needle) return text2;
8903
+ const out = text2.split(needle).join(replacement);
8904
+ if (needle.length < CASE_SWAP_MIN_CHARS) return out;
8905
+ if (!out.toLowerCase().includes(needle.toLowerCase())) return out;
8906
+ return out.replace(
8907
+ standingAlonePattern(needle),
8908
+ (seen) => shaped(replacement, seen)
8909
+ );
8910
+ }
8911
+
8618
8912
  // src/hooks/alias.ts
8619
8913
  import { createHash as createHash10, createHmac, randomBytes as randomBytes2 } from "crypto";
8620
8914
  var GIVEN = [
@@ -9449,10 +9743,9 @@ var AliasMap = class _AliasMap {
9449
9743
  const [inbound] = this.pairs();
9450
9744
  let out = text2;
9451
9745
  for (const [needle, replacement, alias] of inbound) {
9452
- if (needle && out.includes(needle)) {
9453
- out = out.split(needle).join(replacement);
9454
- alias.hitsIn += 1;
9455
- }
9746
+ const swapped = swapValue(out, needle, replacement);
9747
+ if (swapped !== out) alias.hitsIn += 1;
9748
+ out = swapped;
9456
9749
  }
9457
9750
  out = out.replace(SHA256_ANY_GLOBAL, (match) => this.mintDigest(match));
9458
9751
  if (this.mintInbound.length) out = this.mintFoundIn(out, where);
@@ -9468,10 +9761,9 @@ var AliasMap = class _AliasMap {
9468
9761
  const [, outbound] = this.pairs();
9469
9762
  let out = text2;
9470
9763
  for (const [needle, replacement, alias] of outbound) {
9471
- if (needle && out.includes(needle)) {
9472
- out = out.split(needle).join(replacement);
9473
- alias.hitsOut += 1;
9474
- }
9764
+ const swapped = swapValue(out, needle, replacement);
9765
+ if (swapped !== out) alias.hitsOut += 1;
9766
+ out = swapped;
9475
9767
  }
9476
9768
  const problems = [];
9477
9769
  for (const [needle] of outbound) {
@@ -12107,6 +12399,221 @@ var LiveTools = class _LiveTools {
12107
12399
  }
12108
12400
  };
12109
12401
 
12402
+ // src/hooks/audit.ts
12403
+ var MIN_VALUE_CHARS = 4;
12404
+ var REVIEW_MIN_CHARS = 20;
12405
+ var ANY_TOOL = "*";
12406
+ var isObject6 = (node) => typeof node === "object" && node !== null && !Array.isArray(node);
12407
+ function* stringsOf(node) {
12408
+ if (typeof node === "string") {
12409
+ yield node;
12410
+ return;
12411
+ }
12412
+ const children = Array.isArray(node) ? node : isObject6(node) ? Object.values(node) : [];
12413
+ for (const child of children) yield* stringsOf(child);
12414
+ }
12415
+ function* fieldsOf(node) {
12416
+ if (Array.isArray(node)) {
12417
+ for (const child of node) yield* fieldsOf(child);
12418
+ return;
12419
+ }
12420
+ if (!isObject6(node)) return;
12421
+ for (const [key2, value] of Object.entries(node)) {
12422
+ yield [key2, value];
12423
+ yield* fieldsOf(value);
12424
+ }
12425
+ }
12426
+ var Identifier = class {
12427
+ constructor(kind, value, source) {
12428
+ this.kind = kind;
12429
+ this.value = value;
12430
+ this.source = source;
12431
+ }
12432
+ get key() {
12433
+ return folded(this.value);
12434
+ }
12435
+ get prefix() {
12436
+ return this.value.slice(0, 3);
12437
+ }
12438
+ };
12439
+ var IdentifierSource = class {
12440
+ ignored() {
12441
+ return [];
12442
+ }
12443
+ };
12444
+ var LegendSource = class extends IdentifierSource {
12445
+ name = "legend";
12446
+ entries;
12447
+ constructor(legend) {
12448
+ super();
12449
+ this.entries = legend.filter((entry) => entry.real);
12450
+ }
12451
+ collect() {
12452
+ return this.entries.filter((entry) => (entry.role ?? "private") !== "public").map((entry) => new Identifier(entry.kind ?? "reference", String(entry.real), this.name));
12453
+ }
12454
+ ignored() {
12455
+ const open = this.entries.filter((e) => e.role === "public").map((e) => String(e.real));
12456
+ const personas2 = this.entries.filter((e) => e.alias).map((e) => String(e.alias));
12457
+ return [...open, ...personas2];
12458
+ }
12459
+ };
12460
+ var FieldSource = class extends IdentifierSource {
12461
+ constructor(fieldKinds) {
12462
+ super();
12463
+ this.fieldKinds = fieldKinds;
12464
+ }
12465
+ name = "fields";
12466
+ kindsFor(tool) {
12467
+ return { ...this.fieldKinds[ANY_TOOL] ?? {}, ...this.fieldKinds[tool] ?? {} };
12468
+ }
12469
+ *collect(raw) {
12470
+ for (const record of raw) {
12471
+ const kinds = this.kindsFor(String(record.tool ?? ""));
12472
+ for (const [key2, value] of fieldsOf(record.result)) {
12473
+ const kind = kinds[key2];
12474
+ if (kind === void 0) continue;
12475
+ for (const text2 of stringsOf(value)) yield new Identifier(kind, text2, this.name);
12476
+ }
12477
+ }
12478
+ }
12479
+ };
12480
+ var FinderSource = class extends IdentifierSource {
12481
+ name;
12482
+ kinds;
12483
+ constructor(kinds = INBOUND_KINDS) {
12484
+ super();
12485
+ const bad = kinds.filter((kind) => !INBOUND_KINDS.includes(kind));
12486
+ if (bad.length > 0)
12487
+ throw new Error(
12488
+ `${bad.join(", ")} cannot be found by a pattern; only ${INBOUND_KINDS.join(", ")} can`
12489
+ );
12490
+ this.kinds = [...kinds];
12491
+ this.name = `finders:${this.kinds.join(",")}`;
12492
+ }
12493
+ *collect(raw) {
12494
+ for (const record of raw)
12495
+ for (const text2 of stringsOf(record.result))
12496
+ for (const kind of this.kinds)
12497
+ for (const value of findKind(kind, text2)) yield new Identifier(kind, value, "finders");
12498
+ }
12499
+ };
12500
+ var IdentifierCensus = class {
12501
+ constructor(sources) {
12502
+ this.sources = sources;
12503
+ }
12504
+ get detectors() {
12505
+ return this.sources.map((source) => source.name);
12506
+ }
12507
+ build(raw) {
12508
+ const ignored = new Set(this.sources.flatMap((s) => [...s.ignored()].map(folded)));
12509
+ const seen = /* @__PURE__ */ new Map();
12510
+ for (const source of this.sources)
12511
+ for (const identifier of source.collect(raw)) {
12512
+ if (identifier.value.length < MIN_VALUE_CHARS || ignored.has(identifier.key)) continue;
12513
+ if (!seen.has(identifier.key)) seen.set(identifier.key, identifier);
12514
+ }
12515
+ return [...seen.values()];
12516
+ }
12517
+ };
12518
+ function shuffled(items, seed) {
12519
+ const out = [...items];
12520
+ let state2 = seed >>> 0;
12521
+ const next = () => {
12522
+ state2 = state2 + 1831565813 >>> 0;
12523
+ let t = Math.imul(state2 ^ state2 >>> 15, 1 | state2);
12524
+ t = t + Math.imul(t ^ t >>> 7, 61 | t) ^ t;
12525
+ return ((t ^ t >>> 14) >>> 0) / 4294967296;
12526
+ };
12527
+ for (let i = out.length - 1; i > 0; i -= 1) {
12528
+ const j = Math.floor(next() * (i + 1));
12529
+ [out[i], out[j]] = [out[j], out[i]];
12530
+ }
12531
+ return out;
12532
+ }
12533
+ var AuditReport = class {
12534
+ constructor(findings, census, detectors, recordsScanned, leakedIdentifiers, cleanTexts) {
12535
+ this.findings = findings;
12536
+ this.census = census;
12537
+ this.detectors = detectors;
12538
+ this.recordsScanned = recordsScanned;
12539
+ this.leakedIdentifiers = leakedIdentifiers;
12540
+ this.cleanTexts = cleanTexts;
12541
+ }
12542
+ get ok() {
12543
+ return this.findings.length === 0;
12544
+ }
12545
+ get censusTotal() {
12546
+ return this.census.length;
12547
+ }
12548
+ /** The share of census identifiers that did NOT reach the model; 1 for an empty census. */
12549
+ get coverage() {
12550
+ if (this.census.length === 0) return 1;
12551
+ return Math.round((1 - this.leakedIdentifiers / this.census.length) * 1e4) / 1e4;
12552
+ }
12553
+ count(pick3) {
12554
+ const counts = {};
12555
+ for (const identifier of this.census) counts[pick3(identifier)] = (counts[pick3(identifier)] ?? 0) + 1;
12556
+ return counts;
12557
+ }
12558
+ /** `size` strings the model saw that nothing flagged, for a person to read. */
12559
+ reviewSample(size, seed = 0) {
12560
+ const pool = [...this.cleanTexts].sort(
12561
+ (a, b) => a.record - b.record || a.text.localeCompare(b.text)
12562
+ );
12563
+ return shuffled(pool, seed).slice(0, size);
12564
+ }
12565
+ toDict() {
12566
+ return {
12567
+ ok: this.ok,
12568
+ records_scanned: this.recordsScanned,
12569
+ detectors: this.detectors,
12570
+ census: {
12571
+ total: this.censusTotal,
12572
+ by_source: this.count((i) => i.source),
12573
+ by_kind: this.count((i) => i.kind)
12574
+ },
12575
+ leaked_identifiers: this.leakedIdentifiers,
12576
+ coverage: this.coverage,
12577
+ findings: this.findings
12578
+ };
12579
+ }
12580
+ };
12581
+ var RedactionAudit = class _RedactionAudit {
12582
+ constructor(census) {
12583
+ this.census = census;
12584
+ }
12585
+ /** The standard audit: the run's legend, declared field kinds, pattern finders. */
12586
+ static forRun(options) {
12587
+ return new _RedactionAudit(
12588
+ new IdentifierCensus([
12589
+ new LegendSource(options.legend ?? []),
12590
+ new FieldSource(options.fieldKinds ?? {}),
12591
+ new FinderSource(options.finderKinds ?? INBOUND_KINDS)
12592
+ ])
12593
+ );
12594
+ }
12595
+ run(raw, shown) {
12596
+ const census = this.census.build(raw);
12597
+ const findings = [];
12598
+ const clean = [];
12599
+ const leaked = /* @__PURE__ */ new Set();
12600
+ shown.forEach((record, index2) => {
12601
+ const tool = String(record.tool ?? "");
12602
+ const texts = [...stringsOf(record.result)];
12603
+ const haystack = folded(texts.join("\n"));
12604
+ const hits = census.filter((identifier) => haystack.includes(identifier.key));
12605
+ hits.forEach((identifier) => leaked.add(identifier.key));
12606
+ findings.push(
12607
+ ...hits.map((i) => ({ record: index2, tool, kind: i.kind, source: i.source, prefix: i.prefix }))
12608
+ );
12609
+ clean.push(
12610
+ ...texts.filter((t) => t.length >= REVIEW_MIN_CHARS && !hits.some((i) => folded(t).includes(i.key))).map((text2) => ({ record: index2, tool, text: text2 }))
12611
+ );
12612
+ });
12613
+ return new AuditReport(findings, census, this.census.detectors, shown.length, leaked.size, clean);
12614
+ }
12615
+ };
12616
+
12110
12617
  // src/hooks/run.ts
12111
12618
  import { randomBytes as randomBytes3 } from "crypto";
12112
12619
  import * as fs15 from "fs";
@@ -12894,10 +13401,28 @@ function toolResultText(content) {
12894
13401
  ).join("");
12895
13402
  return JSON.stringify(content ?? "");
12896
13403
  }
13404
+ function toolSummary(names) {
13405
+ return names.map((n) => `\u2192 ${n}`).join(", ");
13406
+ }
13407
+ var USAGE_ATTRIBUTES = [
13408
+ ["input_tokens", "llm.token_count.prompt"],
13409
+ ["output_tokens", "llm.token_count.completion"],
13410
+ ["cache_read_input_tokens", "llm.token_count.prompt_details.cache_read"],
13411
+ ["cache_creation_input_tokens", "llm.token_count.prompt_details.cache_write"]
13412
+ ];
13413
+ function setUsageAttributes(span, usage) {
13414
+ if (!usage || typeof usage !== "object") return;
13415
+ const u = usage;
13416
+ for (const [field, attribute] of USAGE_ATTRIBUTES) {
13417
+ const value = u[field];
13418
+ if (typeof value === "number" && Number.isFinite(value))
13419
+ span.setAttribute(attribute, value);
13420
+ }
13421
+ }
12897
13422
  var TURN_INPUT_MAX = 4e3;
12898
13423
  async function* observeClaude(stream, options) {
12899
13424
  const tracer = options.tracer ?? trace4.getTracer("@withgateway/sdk");
12900
- const model = options.model ?? "claude";
13425
+ const fallbackModel = options.model ?? "claude";
12901
13426
  const openTools = /* @__PURE__ */ new Map();
12902
13427
  let root = null;
12903
13428
  let rootCtx = null;
@@ -12915,85 +13440,102 @@ async function* observeClaude(stream, options) {
12915
13440
  let turnCtx = null;
12916
13441
  let turnIndex = 0;
12917
13442
  let turnText = "";
13443
+ let turnTools = [];
12918
13444
  let pendingTurnInput = options.input ?? "";
13445
+ let gen = null;
13446
+ let genMessageId;
13447
+ let genText = "";
13448
+ let genTools = [];
13449
+ let genUsage;
12919
13450
  let finalText = "";
13451
+ const endGeneration = () => {
13452
+ if (!gen) return;
13453
+ gen.setAttribute("output.value", genText || toolSummary(genTools));
13454
+ setUsageAttributes(gen, genUsage);
13455
+ gen.setStatus({ code: SpanStatusCode2.OK });
13456
+ gen.end();
13457
+ gen = null;
13458
+ genMessageId = void 0;
13459
+ genText = "";
13460
+ genTools = [];
13461
+ genUsage = void 0;
13462
+ };
12920
13463
  const endTurn = () => {
12921
13464
  if (!turnRoot) return;
12922
- if (turnText) turnRoot.setAttribute("output.value", turnText);
13465
+ const output = turnText || toolSummary(turnTools);
13466
+ if (output) turnRoot.setAttribute("output.value", output);
12923
13467
  turnRoot.setStatus({ code: SpanStatusCode2.OK });
12924
13468
  turnRoot.end();
12925
13469
  turnRoot = null;
12926
13470
  turnCtx = null;
12927
13471
  };
13472
+ const startTurn = () => {
13473
+ for (const span of openTools.values()) span.end();
13474
+ openTools.clear();
13475
+ endTurn();
13476
+ turnIndex += 1;
13477
+ turnText = "";
13478
+ turnTools = [];
13479
+ turnRoot = tracer.startSpan(`${options.name} \xB7 turn ${turnIndex}`, {
13480
+ root: true,
13481
+ attributes: {
13482
+ "openinference.span.kind": "AGENT",
13483
+ ...pendingTurnInput ? { "input.value": pendingTurnInput.slice(0, TURN_INPUT_MAX) } : {},
13484
+ ...options.attributes ?? {}
13485
+ }
13486
+ });
13487
+ turnCtx = trace4.setSpan(context3.active(), turnRoot);
13488
+ pendingTurnInput = "";
13489
+ };
13490
+ const startGeneration = (message) => {
13491
+ endGeneration();
13492
+ if (options.perTurn) startTurn();
13493
+ const childCtx = options.perTurn ? turnCtx : rootCtx;
13494
+ genMessageId = message.message?.id;
13495
+ gen = tracer.startSpan(
13496
+ "assistant",
13497
+ {
13498
+ attributes: {
13499
+ "openinference.span.kind": "LLM",
13500
+ "llm.model_name": message.message?.model ?? fallbackModel,
13501
+ "llm.provider": "anthropic"
13502
+ }
13503
+ },
13504
+ childCtx
13505
+ );
13506
+ };
12928
13507
  try {
12929
13508
  for await (const message of stream) {
12930
13509
  if (message?.type === "assistant") {
12931
- if (options.perTurn) {
12932
- for (const span of openTools.values()) span.end();
12933
- openTools.clear();
12934
- endTurn();
12935
- turnIndex += 1;
12936
- turnText = "";
12937
- turnRoot = tracer.startSpan(`${options.name} \xB7 turn ${turnIndex}`, {
12938
- root: true,
12939
- attributes: {
12940
- "openinference.span.kind": "AGENT",
12941
- ...pendingTurnInput ? { "input.value": pendingTurnInput.slice(0, TURN_INPUT_MAX) } : {},
12942
- ...options.attributes ?? {}
12943
- }
12944
- });
12945
- turnCtx = trace4.setSpan(context3.active(), turnRoot);
12946
- pendingTurnInput = "";
12947
- }
13510
+ const messageId = message.message?.id;
13511
+ const continuesGeneration = gen !== null && messageId !== void 0 && messageId === genMessageId;
13512
+ if (!continuesGeneration) startGeneration(message);
12948
13513
  const childCtx = options.perTurn ? turnCtx : rootCtx;
12949
- let text2 = "";
12950
- const toolUses = [];
12951
13514
  for (const block of message.message?.content ?? []) {
12952
13515
  if (block?.type === "text") {
12953
13516
  finalText += block.text;
12954
- text2 += block.text;
13517
+ turnText += block.text;
13518
+ genText += block.text;
12955
13519
  }
12956
13520
  if (block?.type === "tool_use") {
12957
- toolUses.push({
12958
- id: block.id,
12959
- name: block.name,
12960
- input: block.input
12961
- });
13521
+ const name = cleanToolName(block.name);
13522
+ genTools.push(name);
13523
+ turnTools.push(name);
13524
+ const span = tracer.startSpan(
13525
+ `tool.${name}`,
13526
+ {
13527
+ attributes: {
13528
+ "openinference.span.kind": "TOOL",
13529
+ "tool.name": name,
13530
+ "input.value": JSON.stringify(block.input)
13531
+ }
13532
+ },
13533
+ childCtx
13534
+ );
13535
+ openTools.set(block.id, span);
12962
13536
  }
12963
13537
  }
12964
- turnText += text2;
12965
- const gen = tracer.startSpan(
12966
- "assistant",
12967
- {
12968
- attributes: {
12969
- "openinference.span.kind": "LLM",
12970
- "llm.model_name": model,
12971
- "llm.provider": "anthropic",
12972
- "output.value": text2 || toolUses.map((t) => `\u2192 ${cleanToolName(t.name)}`).join(", ")
12973
- }
12974
- },
12975
- childCtx
12976
- );
12977
- const usage = message.message?.usage;
12978
- if (usage?.input_tokens != null)
12979
- gen.setAttribute("llm.token_count.prompt", usage.input_tokens);
12980
- if (usage?.output_tokens != null)
12981
- gen.setAttribute("llm.token_count.completion", usage.output_tokens);
12982
- gen.end();
12983
- for (const t of toolUses) {
12984
- const span = tracer.startSpan(
12985
- `tool.${cleanToolName(t.name)}`,
12986
- {
12987
- attributes: {
12988
- "openinference.span.kind": "TOOL",
12989
- "tool.name": cleanToolName(t.name),
12990
- "input.value": JSON.stringify(t.input)
12991
- }
12992
- },
12993
- childCtx
12994
- );
12995
- openTools.set(t.id, span);
12996
- }
13538
+ if (message.message?.usage) genUsage = message.message.usage;
12997
13539
  }
12998
13540
  if (message?.type === "user") {
12999
13541
  const content = message.message?.content;
@@ -13018,6 +13560,7 @@ async function* observeClaude(stream, options) {
13018
13560
  yield message;
13019
13561
  }
13020
13562
  } finally {
13563
+ endGeneration();
13021
13564
  for (const span of openTools.values()) span.end();
13022
13565
  openTools.clear();
13023
13566
  if (options.perTurn) {
@@ -13080,6 +13623,7 @@ export {
13080
13623
  Persona,
13081
13624
  PersonaError,
13082
13625
  PersonasClient,
13626
+ PushSlugConflict,
13083
13627
  REPLAY_ENVIRONMENT,
13084
13628
  ReplayCase,
13085
13629
  ReplayCheck,
@@ -13106,6 +13650,7 @@ export {
13106
13650
  UsersClient,
13107
13651
  WHITESPACE,
13108
13652
  WorldBrowser,
13653
+ WorldSandboxClient,
13109
13654
  WorldSession,
13110
13655
  WorldSessionCallError,
13111
13656
  WorldSessionTimeout,
@@ -13116,12 +13661,14 @@ export {
13116
13661
  aggregateTaskGrade,
13117
13662
  apiRequest,
13118
13663
  applyTransforms,
13664
+ archiveMode,
13119
13665
  assembleManifest,
13120
13666
  assignVariant,
13121
13667
  attachManifest,
13122
13668
  attachSession,
13123
13669
  attachTask,
13124
13670
  basicAuthHeader,
13671
+ buildFileManifest,
13125
13672
  buildSourceTarball,
13126
13673
  canonicalJson,
13127
13674
  captureToolCalls,
@@ -13142,6 +13689,7 @@ export {
13142
13689
  detectProvenance,
13143
13690
  experimentContextStorage,
13144
13691
  singleton_exports as experiments,
13692
+ extractBundle,
13145
13693
  files_exports as files,
13146
13694
  gateway,
13147
13695
  getExperimentContext,
@@ -13173,6 +13721,8 @@ export {
13173
13721
  openSession,
13174
13722
  openTask,
13175
13723
  openWorld,
13724
+ openWorldVersion,
13725
+ parseSlugRef,
13176
13726
  parseToolCallRecord,
13177
13727
  parseTransform,
13178
13728
  parseWorldTaskRefs,
@@ -13196,6 +13746,7 @@ export {
13196
13746
  replay,
13197
13747
  resetBuildRegistry,
13198
13748
  resolveBrowserMode,
13749
+ resolvePushSlug,
13199
13750
  resolveUserId,
13200
13751
  roundForm,
13201
13752
  runSessions,