@withgateway/sdk 0.1.14 → 0.1.17

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.
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
+ var __create = Object.create;
2
3
  var __defProp = Object.defineProperty;
3
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
5
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
8
  var __esm = (fn, res) => function __init() {
7
9
  return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
@@ -18,6 +20,14 @@ var __copyProps = (to, from, except, desc) => {
18
20
  }
19
21
  return to;
20
22
  };
23
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
24
+ // If the importer is in node compatibility mode or this is not an ESM
25
+ // file that has been converted to a CommonJS file using a Babel-
26
+ // compatible transform (i.e. "__esModule" has not been set), then set
27
+ // "default" to the CommonJS "module.exports" for node compatibility.
28
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
29
+ mod
30
+ ));
21
31
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
22
32
 
23
33
  // src/worlds/session.ts
@@ -315,9 +325,524 @@ var init_session = __esm({
315
325
  }
316
326
  });
317
327
 
328
+ // src/worlds/hub.ts
329
+ function isExcludedDirComponent(component) {
330
+ return component.startsWith(".") || ROOT_EXCLUDED_DIRS.has(component) || component.endsWith(".egg-info");
331
+ }
332
+ function isIncludedInContentHash(relPath, includeAllRootFiles) {
333
+ const parts = relPath.split("/");
334
+ const name = parts[parts.length - 1];
335
+ const dirParts = parts.slice(0, -1);
336
+ if (name.startsWith(".")) return false;
337
+ if (parts.includes("__pycache__")) return false;
338
+ if (dirParts.length === 0) {
339
+ return includeAllRootFiles || name === "README.md" || name === "pyproject.toml" || name === "gateway-env.toml" || name.endsWith(".py");
340
+ }
341
+ return !dirParts.some(isExcludedDirComponent);
342
+ }
343
+ function collectArchiveRelPaths(dir) {
344
+ if (fs.existsSync(path.join(dir, ".gitignore"))) {
345
+ throw new Error(
346
+ "This bundle has a root .gitignore, which the Python CLI honors via gitignore_parser. Reimplementing that imperfectly here would silently produce a different content hash, so the TS CLI refuses. Remove the .gitignore (or bake its effect into the tree) and retry."
347
+ );
348
+ }
349
+ const out = [];
350
+ const includeAllRootFiles = fs.existsSync(path.join(dir, "gateway-env.toml"));
351
+ const walk = (rel) => {
352
+ const abs = rel ? path.join(dir, rel) : dir;
353
+ for (const entry of fs.readdirSync(abs, { withFileTypes: true }).sort((a, b) => a.name.localeCompare(b.name))) {
354
+ const childRel = rel ? `${rel}/${entry.name}` : entry.name;
355
+ if (entry.isDirectory()) {
356
+ if (!isExcludedDirComponent(entry.name)) walk(childRel);
357
+ } else if (entry.isFile()) {
358
+ if (isIncludedInContentHash(childRel, includeAllRootFiles)) {
359
+ out.push(childRel);
360
+ }
361
+ }
362
+ }
363
+ };
364
+ walk("");
365
+ return out.sort((a, b) => a < b ? -1 : a > b ? 1 : 0);
366
+ }
367
+ function computeContentHash(dir) {
368
+ const hasher = (0, import_node_crypto.createHash)("sha256");
369
+ for (const relPath of collectArchiveRelPaths(dir)) {
370
+ hasher.update(Buffer.from(`file:${relPath}`, "utf-8"));
371
+ hasher.update(fs.readFileSync(path.join(dir, relPath)));
372
+ }
373
+ return hasher.digest("hex");
374
+ }
375
+ function octal(value, length) {
376
+ return Buffer.from(value.toString(8).padStart(length - 1, "0") + "\0", "ascii");
377
+ }
378
+ function tarHeader(name, size) {
379
+ const header = Buffer.alloc(512);
380
+ header.write(name, 0, 100, "utf-8");
381
+ octal(420, 8).copy(header, 100);
382
+ octal(0, 8).copy(header, 108);
383
+ octal(0, 8).copy(header, 116);
384
+ octal(size, 12).copy(header, 124);
385
+ octal(0, 12).copy(header, 136);
386
+ header.write(" ", 148, "ascii");
387
+ header.write("0", 156, "ascii");
388
+ header.write("ustar", 257, "ascii");
389
+ header.write("00", 263, "ascii");
390
+ let sum = 0;
391
+ for (const byte of header) sum += byte;
392
+ header.write(sum.toString(8).padStart(6, "0") + "\0 ", 148, "ascii");
393
+ return header;
394
+ }
395
+ function tarMember(name, payload) {
396
+ const parts = [];
397
+ const nameBytes = Buffer.byteLength(name, "utf-8");
398
+ if (nameBytes > 100) {
399
+ const body = Buffer.from(name + "\0", "utf-8");
400
+ const lHeader = tarHeader("././@LongLink", body.length);
401
+ lHeader.write("L", 156, "ascii");
402
+ let sum = 0;
403
+ lHeader.write(" ", 148, "ascii");
404
+ for (const byte of lHeader) sum += byte;
405
+ lHeader.write(sum.toString(8).padStart(6, "0") + "\0 ", 148, "ascii");
406
+ parts.push(lHeader, body);
407
+ const pad2 = body.length % 512 === 0 ? 0 : 512 - body.length % 512;
408
+ if (pad2) parts.push(Buffer.alloc(pad2));
409
+ parts.push(tarHeader(name.slice(0, 100), payload.length));
410
+ } else {
411
+ parts.push(tarHeader(name, payload.length));
412
+ }
413
+ parts.push(payload);
414
+ const pad = payload.length % 512 === 0 ? 0 : 512 - payload.length % 512;
415
+ if (pad) parts.push(Buffer.alloc(pad));
416
+ return parts;
417
+ }
418
+ function buildSourceTarball(dir) {
419
+ const parts = [];
420
+ for (const relPath of collectArchiveRelPaths(dir)) {
421
+ parts.push(...tarMember(relPath, fs.readFileSync(path.join(dir, relPath))));
422
+ }
423
+ parts.push(Buffer.alloc(1024));
424
+ return (0, import_node_zlib.gzipSync)(Buffer.concat(parts), { level: 9 });
425
+ }
426
+ function readLocalMeta(dir) {
427
+ try {
428
+ const raw = fs.readFileSync(path.join(dir, META_RELPATH), "utf-8");
429
+ const parsed = JSON.parse(raw);
430
+ return parsed && typeof parsed === "object" ? parsed : null;
431
+ } catch {
432
+ return null;
433
+ }
434
+ }
435
+ function writeLocalMeta(dir, meta) {
436
+ fs.mkdirSync(path.join(dir, ".gateway"), { recursive: true });
437
+ fs.writeFileSync(path.join(dir, META_RELPATH), JSON.stringify(meta, null, 2));
438
+ }
439
+ function snapshotTreeHashes(dir) {
440
+ const out = {};
441
+ for (const relPath of collectArchiveRelPaths(dir)) {
442
+ out[relPath] = (0, import_node_crypto.createHash)("sha256").update(fs.readFileSync(path.join(dir, relPath))).digest("hex");
443
+ }
444
+ return out;
445
+ }
446
+ function localTreeState(dir) {
447
+ const meta = readLocalMeta(dir);
448
+ const base = meta?.baseFiles;
449
+ if (!base || typeof base !== "object") {
450
+ return { meta, dirty: [], clean: false };
451
+ }
452
+ const now = snapshotTreeHashes(dir);
453
+ const dirty = /* @__PURE__ */ new Set();
454
+ for (const [p, h] of Object.entries(now)) if (base[p] !== h) dirty.add(p);
455
+ for (const p of Object.keys(base)) if (!(p in now)) dirty.add(p);
456
+ return { meta, dirty: [...dirty].sort(), clean: dirty.size === 0 };
457
+ }
458
+ function readPyproject(dir) {
459
+ try {
460
+ const text = fs.readFileSync(path.join(dir, "pyproject.toml"), "utf-8");
461
+ const section = /\[project\]([\s\S]*?)(\n\[|$)/.exec(text)?.[1] ?? "";
462
+ const name = /\bname\s*=\s*"([^"]+)"/.exec(section)?.[1];
463
+ const version = /\bversion\s*=\s*"([^"]+)"/.exec(section)?.[1];
464
+ return { name, version };
465
+ } catch {
466
+ return {};
467
+ }
468
+ }
469
+ function buildFileManifest(dir) {
470
+ const entries = [];
471
+ const walk = (rel) => {
472
+ const abs = rel ? path.join(dir, rel) : dir;
473
+ for (const entry of fs.readdirSync(abs, { withFileTypes: true }).sort((a, b) => a.name.localeCompare(b.name))) {
474
+ const childRel = rel ? `${rel}/${entry.name}` : entry.name;
475
+ if (entry.isDirectory()) {
476
+ if (!SKIP_DIRS.has(entry.name) && !entry.name.endsWith(".egg-info")) {
477
+ walk(childRel);
478
+ }
479
+ } else if (entry.isFile()) {
480
+ const payload = fs.readFileSync(path.join(dir, childRel));
481
+ entries.push({
482
+ path: childRel,
483
+ isDirectory: false,
484
+ size: payload.length,
485
+ sha256: (0, import_node_crypto.createHash)("sha256").update(payload).digest("hex")
486
+ });
487
+ }
488
+ }
489
+ };
490
+ walk("");
491
+ return entries;
492
+ }
493
+ async function putObject(url, data, shaB64) {
494
+ const resp = await fetch(url, {
495
+ method: "PUT",
496
+ headers: {
497
+ "Content-Type": "application/gzip",
498
+ "x-amz-checksum-sha256": shaB64
499
+ },
500
+ body: new Uint8Array(data)
501
+ });
502
+ if (!resp.ok) {
503
+ throw new Error(`object PUT -> ${resp.status}: ${(await resp.text()).slice(0, 300)}`);
504
+ }
505
+ }
506
+ async function push(dir, opts = {}) {
507
+ const options = opts.options ?? {};
508
+ if (!fs.statSync(dir).isDirectory()) throw new Error(`Not a directory: ${dir}`);
509
+ const localMeta = readLocalMeta(dir) ?? {};
510
+ const branch = opts.branch ?? localMeta.branch ?? DEFAULT_BRANCH;
511
+ const baseVersionId = localMeta.versionId ?? null;
512
+ const contentHash = computeContentHash(dir);
513
+ const pyproject = readPyproject(dir);
514
+ const slug = opts.slug ?? pyproject.name ?? path.basename(path.resolve(dir));
515
+ const resolve2 = await apiRequest(
516
+ options,
517
+ "POST",
518
+ "/api/public/benchmark-containers/resolve",
519
+ { slug, name: pyproject.name ?? slug }
520
+ );
521
+ const tarball = buildSourceTarball(dir);
522
+ const bundleSha256 = sha256b64(tarball);
523
+ const version = await apiRequest(options, "POST", "/api/public/benchmark-containers/versions", {
524
+ containerId: resolve2.containerId,
525
+ contentHash,
526
+ bundleSha256,
527
+ bundleSizeBytes: tarball.length,
528
+ ...pyproject.version ? { semanticVersion: pyproject.version } : {},
529
+ pyprojectMeta: pyproject,
530
+ fileManifest: buildFileManifest(dir),
531
+ branch,
532
+ baseVersionId,
533
+ ...opts.force ? { force: true } : {},
534
+ ...opts.message ? { changeReason: opts.message } : {},
535
+ ...opts.author ? { author: opts.author } : {}
536
+ });
537
+ if (version.uploadUrl) await putObject(version.uploadUrl, tarball, bundleSha256);
538
+ await apiRequest(
539
+ options,
540
+ "POST",
541
+ `/api/public/benchmark-containers/versions/${version.versionId}/finalize`,
542
+ { branch, baseVersionId, ...opts.force ? { force: true } : {} }
543
+ );
544
+ writeLocalMeta(dir, {
545
+ ...localMeta,
546
+ slug,
547
+ ref: branch,
548
+ branch,
549
+ versionId: version.versionId,
550
+ contentHash,
551
+ semanticVersion: pyproject.version,
552
+ forkedFromVersionId: baseVersionId,
553
+ baseFiles: snapshotTreeHashes(dir)
554
+ });
555
+ return { slug, versionId: version.versionId, contentHash, branch };
556
+ }
557
+ function extractBundle(bundle, dir) {
558
+ const tar = (0, import_node_zlib.gunzipSync)(bundle);
559
+ let offset = 0;
560
+ let longName = null;
561
+ let written = 0;
562
+ while (offset + 512 <= tar.length) {
563
+ const header = tar.subarray(offset, offset + 512);
564
+ offset += 512;
565
+ if (header.every((b) => b === 0)) break;
566
+ const rawName = header.subarray(0, 100).toString("utf-8").replace(/\0.*$/, "");
567
+ const size = parseInt(header.subarray(124, 136).toString("ascii").replace(/\0.*$/, "").trim(), 8) || 0;
568
+ const typeflag = header.subarray(156, 157).toString("ascii");
569
+ const body = tar.subarray(offset, offset + size);
570
+ offset += size + (size % 512 === 0 ? 0 : 512 - size % 512);
571
+ if (typeflag === "L") {
572
+ longName = body.toString("utf-8").replace(/\0.*$/, "");
573
+ continue;
574
+ }
575
+ const name = (longName ?? rawName).replace(/^\.\//, "");
576
+ longName = null;
577
+ if (typeflag !== "0" && typeflag !== "") continue;
578
+ if (name.startsWith("/") || name.split("/").includes("..")) continue;
579
+ const target = path.join(dir, name);
580
+ fs.mkdirSync(path.dirname(target), { recursive: true });
581
+ fs.writeFileSync(target, body);
582
+ written++;
583
+ }
584
+ return written;
585
+ }
586
+ async function pull(slugRef, target, options = {}) {
587
+ const at = slugRef.indexOf("@");
588
+ const slug = at === -1 ? slugRef : slugRef.slice(0, at);
589
+ const ref = at === -1 ? "latest" : slugRef.slice(at + 1);
590
+ const details = await apiRequest(options, "POST", "/api/public/benchmark-containers/resolve-version", {
591
+ slug,
592
+ ref
593
+ });
594
+ if (!details.downloadUrl) {
595
+ throw new Error(`${slug}@${ref} resolved but has no uploaded bundle`);
596
+ }
597
+ let dir = target ?? path.join(process.cwd(), slug);
598
+ if (!target) {
599
+ let i = 1;
600
+ const base = dir;
601
+ while (fs.existsSync(dir)) dir = `${base}-${i++}`;
602
+ }
603
+ fs.mkdirSync(dir, { recursive: true });
604
+ const resp = await fetch(details.downloadUrl);
605
+ if (!resp.ok) throw new Error(`bundle download -> ${resp.status}`);
606
+ const bundle = Buffer.from(await resp.arrayBuffer());
607
+ if (details.bundleSha256 && sha256b64(bundle) !== details.bundleSha256) {
608
+ throw new Error(
609
+ `bundle integrity check failed for ${slug}@${ref}: downloaded sha256 != recorded bundleSha256`
610
+ );
611
+ }
612
+ const files = extractBundle(bundle, dir);
613
+ const branch = ref === "latest" || /^\d|^[0-9a-f]{8,}$/.test(ref) ? DEFAULT_BRANCH : ref;
614
+ writeLocalMeta(dir, {
615
+ slug,
616
+ ref,
617
+ branch,
618
+ versionId: details.versionId,
619
+ contentHash: details.contentHash,
620
+ semanticVersion: details.semanticVersion ?? void 0,
621
+ baseFiles: snapshotTreeHashes(dir)
622
+ });
623
+ return { slug, dir, versionId: details.versionId, files };
624
+ }
625
+ async function propose(dir, opts) {
626
+ const meta = readLocalMeta(dir);
627
+ if (!meta?.slug || !meta.baseFiles) {
628
+ throw new Error("This dir has no pull/push base \u2014 run pull first, then edit, then propose.");
629
+ }
630
+ const state = localTreeState(dir);
631
+ if (state.clean) throw new Error("Nothing to propose \u2014 the tree matches its base.");
632
+ const changes = state.dirty.map((relPath) => {
633
+ const abs = path.join(dir, relPath);
634
+ if (!fs.existsSync(abs)) return { path: relPath, action: "delete" };
635
+ return {
636
+ path: relPath,
637
+ action: "write",
638
+ newContent: fs.readFileSync(abs, "utf-8")
639
+ };
640
+ });
641
+ const res = await apiRequest(
642
+ opts.options ?? {},
643
+ "POST",
644
+ "/api/public/benchmark-containers/proposals",
645
+ {
646
+ slug: meta.slug,
647
+ title: opts.title,
648
+ changeReason: opts.reason,
649
+ baseVersionId: meta.versionId,
650
+ ...opts.targetBranch ? { targetBranch: opts.targetBranch } : {},
651
+ changes
652
+ }
653
+ );
654
+ return res;
655
+ }
656
+ async function createRef(slug, name, kind, versionId, options = {}) {
657
+ return apiRequest(options, "POST", "/api/public/benchmark-containers/refs", {
658
+ slug,
659
+ name,
660
+ kind,
661
+ ...versionId ? { versionId } : {}
662
+ });
663
+ }
664
+ var import_node_crypto, import_node_zlib, fs, path, DEFAULT_BRANCH, META_RELPATH, SKIP_DIRS, ROOT_EXCLUDED_DIRS, sha256b64;
665
+ var init_hub = __esm({
666
+ "src/worlds/hub.ts"() {
667
+ "use strict";
668
+ import_node_crypto = require("crypto");
669
+ import_node_zlib = require("zlib");
670
+ fs = __toESM(require("fs"));
671
+ path = __toESM(require("path"));
672
+ init_worlds();
673
+ DEFAULT_BRANCH = "main";
674
+ META_RELPATH = path.join(".gateway", ".env-metadata.json");
675
+ SKIP_DIRS = /* @__PURE__ */ new Set([
676
+ ".git",
677
+ "__pycache__",
678
+ "node_modules",
679
+ ".venv",
680
+ ".mypy_cache",
681
+ "dist",
682
+ "build",
683
+ "outputs"
684
+ ]);
685
+ ROOT_EXCLUDED_DIRS = /* @__PURE__ */ new Set(["dist", "build", "outputs", "__pycache__"]);
686
+ sha256b64 = (data) => (0, import_node_crypto.createHash)("sha256").update(data).digest("base64");
687
+ }
688
+ });
689
+
690
+ // src/worlds/validate.ts
691
+ function fmtScore(score) {
692
+ return score === null ? "no score" : score.toFixed(3);
693
+ }
694
+ function buildMarkdown(report, minScore) {
695
+ const lines = [];
696
+ lines.push(
697
+ `### World validation ${report.ok ? "passed" : "failed"} \u2014 \`${report.slug}@${report.branch}\``
698
+ );
699
+ lines.push("");
700
+ lines.push(
701
+ `Ran the pull request's own world source (version \`${report.contentHash.slice(0, 12)}\`) through run config **${report.runConfig.name}**` + (minScore !== null ? `, gating at score \u2265 ${minScore}.` : ".")
702
+ );
703
+ lines.push("");
704
+ lines.push("| Model | Status | Score | Run |");
705
+ lines.push("| --- | --- | ---: | --- |");
706
+ for (const run of report.runs) {
707
+ const r = run.report;
708
+ const link = r?.url ? `[open](${r.url})` : "\u2014";
709
+ const status = run.failure ? `\u274C ${run.failure}` : `\u2705 ${r?.status ?? "COMPLETED"}`;
710
+ lines.push(
711
+ `| \`${run.model}\` | ${status} | ${fmtScore(r?.score ?? null)} | ${link} |`
712
+ );
713
+ }
714
+ const taskRows = report.runs.flatMap(
715
+ (run) => (run.report?.samples ?? []).map((sample) => ({
716
+ model: run.model,
717
+ task: sample.task ?? "?",
718
+ reward: sample.reward
719
+ }))
720
+ );
721
+ if (taskRows.length > 0 && taskRows.length <= 40) {
722
+ lines.push("");
723
+ lines.push("<details><summary>Per-task rewards</summary>");
724
+ lines.push("");
725
+ lines.push("| Task | Model | Reward |");
726
+ lines.push("| --- | --- | ---: |");
727
+ for (const row of taskRows) {
728
+ lines.push(
729
+ `| ${row.task} | \`${row.model}\` | ${row.reward === null ? "no score" : row.reward.toFixed(2)} |`
730
+ );
731
+ }
732
+ lines.push("");
733
+ lines.push("</details>");
734
+ }
735
+ return lines.join("\n");
736
+ }
737
+ async function validateWorld(dir, opts) {
738
+ const options = opts.options ?? {};
739
+ const progress = opts.onProgress ?? (() => {
740
+ });
741
+ const minScore = opts.minScore ?? null;
742
+ const provenance = detectProvenance();
743
+ const branch = opts.branch ?? provenance.branch;
744
+ if (!branch)
745
+ throw new Error(
746
+ "No branch to validate on: pass --branch or run inside a git checkout / GitHub Actions."
747
+ );
748
+ progress(`pushing ${dir} as ${opts.slug ?? "(pyproject name)"}@${branch}\u2026`);
749
+ const pushed = await push(dir, {
750
+ slug: opts.slug,
751
+ branch,
752
+ message: `PR validation push (${provenance.commit?.slice(0, 12) ?? "local"})`,
753
+ ...provenance.actor?.name ? { author: provenance.actor.name } : {},
754
+ options
755
+ });
756
+ progress(`pushed version ${pushed.versionId} (${pushed.contentHash.slice(0, 12)})`);
757
+ const configs = await listRunConfigs(options);
758
+ const runConfig = configs.find((c) => c.id === opts.runConfig) ?? configs.find((c) => c.name === opts.runConfig);
759
+ if (!runConfig) {
760
+ const known = configs.map((c) => c.name).join(", ") || "(none)";
761
+ throw new Error(
762
+ `Run config "${opts.runConfig}" not found in this project. Have: ${known}`
763
+ );
764
+ }
765
+ progress(`dispatching run config "${runConfig.name}" (${runConfig.models.join(", ")})\u2026`);
766
+ const dispatched = await apiRequest(options, "POST", "/api/public/benchmark-containers/run-configs/dispatch", {
767
+ runConfigId: runConfig.id,
768
+ versionId: pushed.versionId,
769
+ ...provenance
770
+ });
771
+ const host = (options.host ?? process.env.GATEWAY_HOST ?? "https://withgateway.ai").replace(/\/+$/, "");
772
+ let projectId = null;
773
+ try {
774
+ const projects = await apiRequest(
775
+ options,
776
+ "GET",
777
+ "/api/public/projects"
778
+ );
779
+ projectId = projects.data?.[0]?.id ?? null;
780
+ } catch {
781
+ projectId = null;
782
+ }
783
+ const fallbackUrl = (report) => {
784
+ if (report.url) return report.url;
785
+ const evaluationId = report.evaluations[0]?.id;
786
+ return projectId && evaluationId ? `${host}/project/${projectId}/environment/runs/${encodeURIComponent(evaluationId)}` : null;
787
+ };
788
+ const runs = [];
789
+ for (const run of dispatched.runs) {
790
+ if (!run.ok) {
791
+ runs.push({
792
+ model: run.model,
793
+ runId: run.runId,
794
+ report: null,
795
+ failure: `dispatch failed: ${run.error ?? "unknown error"}`
796
+ });
797
+ continue;
798
+ }
799
+ progress(`waiting on ${run.model} (run ${run.runId})\u2026`);
800
+ let report = null;
801
+ let failure = null;
802
+ try {
803
+ report = await waitForRun(run.runId, {
804
+ timeoutMinutes: opts.timeoutMinutes ?? 45,
805
+ options,
806
+ onTick: (r) => progress(
807
+ `\u2026${run.model}: ${r.status.toLowerCase()} (${r.shardsCompleted ?? 0}/${r.parallelism} shards)`
808
+ )
809
+ });
810
+ report = { ...report, url: fallbackUrl(report) };
811
+ if (report.status.toUpperCase() !== "COMPLETED") {
812
+ failure = report.status;
813
+ } else if (minScore !== null) {
814
+ if (report.score === null) failure = "completed without a score";
815
+ else if (report.score < minScore)
816
+ failure = `score ${fmtScore(report.score)} < ${minScore}`;
817
+ }
818
+ } catch (error) {
819
+ failure = error instanceof Error ? error.message : String(error);
820
+ }
821
+ runs.push({ model: run.model, runId: run.runId, report, failure });
822
+ }
823
+ const base = {
824
+ ok: runs.length > 0 && runs.every((r) => r.failure === null),
825
+ slug: pushed.slug,
826
+ branch,
827
+ versionId: pushed.versionId,
828
+ contentHash: pushed.contentHash,
829
+ runConfig: { id: runConfig.id, name: runConfig.name },
830
+ runs
831
+ };
832
+ return { ...base, markdown: buildMarkdown(base, minScore) };
833
+ }
834
+ var init_validate = __esm({
835
+ "src/worlds/validate.ts"() {
836
+ "use strict";
837
+ init_worlds();
838
+ init_hub();
839
+ }
840
+ });
841
+
318
842
  // src/worlds/index.ts
319
843
  var worlds_exports = {};
320
844
  __export(worlds_exports, {
845
+ DEFAULT_BRANCH: () => DEFAULT_BRANCH,
321
846
  WorldSession: () => WorldSession,
322
847
  WorldSessionCallError: () => WorldSessionCallError,
323
848
  WorldSessionTimeout: () => WorldSessionTimeout,
@@ -325,17 +850,30 @@ __export(worlds_exports, {
325
850
  WorldTask: () => WorldTask,
326
851
  apiRequest: () => apiRequest,
327
852
  attachSession: () => attachSession,
853
+ buildSourceTarball: () => buildSourceTarball,
854
+ collectArchiveRelPaths: () => collectArchiveRelPaths,
855
+ computeContentHash: () => computeContentHash,
856
+ createRef: () => createRef,
328
857
  deleteEnvSecret: () => deleteEnvSecret,
329
858
  detectProvenance: () => detectProvenance,
330
859
  getRun: () => getRun,
860
+ isIncludedInContentHash: () => isIncludedInContentHash,
331
861
  listEnvSecretKeys: () => listEnvSecretKeys,
332
862
  listRunConfigs: () => listRunConfigs,
863
+ localTreeState: () => localTreeState,
333
864
  openSession: () => openSession,
334
865
  openWorld: () => openWorld,
866
+ propose: () => propose,
867
+ pull: () => pull,
868
+ push: () => push,
869
+ readLocalMeta: () => readLocalMeta,
335
870
  runSessions: () => runSessions,
336
871
  schemaFromSignature: () => schemaFromSignature,
337
872
  setEnvSecret: () => setEnvSecret,
338
- waitForRun: () => waitForRun
873
+ snapshotTreeHashes: () => snapshotTreeHashes,
874
+ validateWorld: () => validateWorld,
875
+ waitForRun: () => waitForRun,
876
+ writeLocalMeta: () => writeLocalMeta
339
877
  });
340
878
  module.exports = __toCommonJS(worlds_exports);
341
879
  function resolveEnv(options) {
@@ -349,9 +887,9 @@ function resolveEnv(options) {
349
887
  }
350
888
  return { host: host.replace(/\/+$/, ""), publicKey, secretKey };
351
889
  }
352
- async function apiRequest(options, method, path, body) {
890
+ async function apiRequest(options, method, path2, body) {
353
891
  const { host, publicKey, secretKey } = resolveEnv(options);
354
- const res = await fetch(`${host}${path}`, {
892
+ const res = await fetch(`${host}${path2}`, {
355
893
  method,
356
894
  headers: {
357
895
  "content-type": "application/json",
@@ -362,7 +900,7 @@ async function apiRequest(options, method, path, body) {
362
900
  const text = await res.text();
363
901
  if (!res.ok) {
364
902
  throw new Error(
365
- `${method} ${path} -> ${res.status}: ${text.slice(0, 400)}`
903
+ `${method} ${path2} -> ${res.status}: ${text.slice(0, 400)}`
366
904
  );
367
905
  }
368
906
  return JSON.parse(text);
@@ -424,7 +962,7 @@ async function waitForRun(runId, opts = {}) {
424
962
  );
425
963
  opts.onTick?.(run);
426
964
  await new Promise(
427
- (resolve) => setTimeout(resolve, (opts.intervalSeconds ?? 20) * 1e3)
965
+ (resolve2) => setTimeout(resolve2, (opts.intervalSeconds ?? 20) * 1e3)
428
966
  );
429
967
  }
430
968
  }
@@ -498,6 +1036,8 @@ var WorldTask, WorldSet;
498
1036
  var init_worlds = __esm({
499
1037
  "src/worlds/index.ts"() {
500
1038
  init_session();
1039
+ init_hub();
1040
+ init_validate();
501
1041
  WorldTask = class {
502
1042
  constructor(world, name, variant) {
503
1043
  this.world = world;
@@ -562,6 +1102,7 @@ var init_worlds = __esm({
562
1102
  init_worlds();
563
1103
  // Annotate the CommonJS export names for ESM import in node:
564
1104
  0 && (module.exports = {
1105
+ DEFAULT_BRANCH,
565
1106
  WorldSession,
566
1107
  WorldSessionCallError,
567
1108
  WorldSessionTimeout,
@@ -569,16 +1110,29 @@ init_worlds();
569
1110
  WorldTask,
570
1111
  apiRequest,
571
1112
  attachSession,
1113
+ buildSourceTarball,
1114
+ collectArchiveRelPaths,
1115
+ computeContentHash,
1116
+ createRef,
572
1117
  deleteEnvSecret,
573
1118
  detectProvenance,
574
1119
  getRun,
1120
+ isIncludedInContentHash,
575
1121
  listEnvSecretKeys,
576
1122
  listRunConfigs,
1123
+ localTreeState,
577
1124
  openSession,
578
1125
  openWorld,
1126
+ propose,
1127
+ pull,
1128
+ push,
1129
+ readLocalMeta,
579
1130
  runSessions,
580
1131
  schemaFromSignature,
581
1132
  setEnvSecret,
582
- waitForRun
1133
+ snapshotTreeHashes,
1134
+ validateWorld,
1135
+ waitForRun,
1136
+ writeLocalMeta
583
1137
  });
584
1138
  //# sourceMappingURL=index.js.map