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