@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.js
CHANGED
|
@@ -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,506 @@ 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 runs = [];
|
|
772
|
+
for (const run of dispatched.runs) {
|
|
773
|
+
if (!run.ok) {
|
|
774
|
+
runs.push({
|
|
775
|
+
model: run.model,
|
|
776
|
+
runId: run.runId,
|
|
777
|
+
report: null,
|
|
778
|
+
failure: `dispatch failed: ${run.error ?? "unknown error"}`
|
|
779
|
+
});
|
|
780
|
+
continue;
|
|
781
|
+
}
|
|
782
|
+
progress(`waiting on ${run.model} (run ${run.runId})\u2026`);
|
|
783
|
+
let report = null;
|
|
784
|
+
let failure = null;
|
|
785
|
+
try {
|
|
786
|
+
report = await waitForRun(run.runId, {
|
|
787
|
+
timeoutMinutes: opts.timeoutMinutes ?? 45,
|
|
788
|
+
options,
|
|
789
|
+
onTick: (r) => progress(
|
|
790
|
+
`\u2026${run.model}: ${r.status.toLowerCase()} (${r.shardsCompleted ?? 0}/${r.parallelism} shards)`
|
|
791
|
+
)
|
|
792
|
+
});
|
|
793
|
+
if (report.status.toUpperCase() !== "COMPLETED") {
|
|
794
|
+
failure = report.status;
|
|
795
|
+
} else if (minScore !== null) {
|
|
796
|
+
if (report.score === null) failure = "completed without a score";
|
|
797
|
+
else if (report.score < minScore)
|
|
798
|
+
failure = `score ${fmtScore(report.score)} < ${minScore}`;
|
|
799
|
+
}
|
|
800
|
+
} catch (error) {
|
|
801
|
+
failure = error instanceof Error ? error.message : String(error);
|
|
802
|
+
}
|
|
803
|
+
runs.push({ model: run.model, runId: run.runId, report, failure });
|
|
804
|
+
}
|
|
805
|
+
const base = {
|
|
806
|
+
ok: runs.length > 0 && runs.every((r) => r.failure === null),
|
|
807
|
+
slug: pushed.slug,
|
|
808
|
+
branch,
|
|
809
|
+
versionId: pushed.versionId,
|
|
810
|
+
contentHash: pushed.contentHash,
|
|
811
|
+
runConfig: { id: runConfig.id, name: runConfig.name },
|
|
812
|
+
runs
|
|
813
|
+
};
|
|
814
|
+
return { ...base, markdown: buildMarkdown(base, minScore) };
|
|
815
|
+
}
|
|
816
|
+
var init_validate = __esm({
|
|
817
|
+
"src/worlds/validate.ts"() {
|
|
818
|
+
"use strict";
|
|
819
|
+
init_worlds();
|
|
820
|
+
init_hub();
|
|
821
|
+
}
|
|
822
|
+
});
|
|
823
|
+
|
|
318
824
|
// src/worlds/index.ts
|
|
319
825
|
var worlds_exports = {};
|
|
320
826
|
__export(worlds_exports, {
|
|
827
|
+
DEFAULT_BRANCH: () => DEFAULT_BRANCH,
|
|
321
828
|
WorldSession: () => WorldSession,
|
|
322
829
|
WorldSessionCallError: () => WorldSessionCallError,
|
|
323
830
|
WorldSessionTimeout: () => WorldSessionTimeout,
|
|
@@ -325,17 +832,30 @@ __export(worlds_exports, {
|
|
|
325
832
|
WorldTask: () => WorldTask,
|
|
326
833
|
apiRequest: () => apiRequest,
|
|
327
834
|
attachSession: () => attachSession,
|
|
835
|
+
buildSourceTarball: () => buildSourceTarball,
|
|
836
|
+
collectArchiveRelPaths: () => collectArchiveRelPaths,
|
|
837
|
+
computeContentHash: () => computeContentHash,
|
|
838
|
+
createRef: () => createRef,
|
|
328
839
|
deleteEnvSecret: () => deleteEnvSecret,
|
|
329
840
|
detectProvenance: () => detectProvenance,
|
|
330
841
|
getRun: () => getRun,
|
|
842
|
+
isIncludedInContentHash: () => isIncludedInContentHash,
|
|
331
843
|
listEnvSecretKeys: () => listEnvSecretKeys,
|
|
332
844
|
listRunConfigs: () => listRunConfigs,
|
|
845
|
+
localTreeState: () => localTreeState,
|
|
333
846
|
openSession: () => openSession,
|
|
334
847
|
openWorld: () => openWorld,
|
|
848
|
+
propose: () => propose,
|
|
849
|
+
pull: () => pull,
|
|
850
|
+
push: () => push,
|
|
851
|
+
readLocalMeta: () => readLocalMeta,
|
|
335
852
|
runSessions: () => runSessions,
|
|
336
853
|
schemaFromSignature: () => schemaFromSignature,
|
|
337
854
|
setEnvSecret: () => setEnvSecret,
|
|
338
|
-
|
|
855
|
+
snapshotTreeHashes: () => snapshotTreeHashes,
|
|
856
|
+
validateWorld: () => validateWorld,
|
|
857
|
+
waitForRun: () => waitForRun,
|
|
858
|
+
writeLocalMeta: () => writeLocalMeta
|
|
339
859
|
});
|
|
340
860
|
module.exports = __toCommonJS(worlds_exports);
|
|
341
861
|
function resolveEnv(options) {
|
|
@@ -349,9 +869,9 @@ function resolveEnv(options) {
|
|
|
349
869
|
}
|
|
350
870
|
return { host: host.replace(/\/+$/, ""), publicKey, secretKey };
|
|
351
871
|
}
|
|
352
|
-
async function apiRequest(options, method,
|
|
872
|
+
async function apiRequest(options, method, path2, body) {
|
|
353
873
|
const { host, publicKey, secretKey } = resolveEnv(options);
|
|
354
|
-
const res = await fetch(`${host}${
|
|
874
|
+
const res = await fetch(`${host}${path2}`, {
|
|
355
875
|
method,
|
|
356
876
|
headers: {
|
|
357
877
|
"content-type": "application/json",
|
|
@@ -362,7 +882,7 @@ async function apiRequest(options, method, path, body) {
|
|
|
362
882
|
const text = await res.text();
|
|
363
883
|
if (!res.ok) {
|
|
364
884
|
throw new Error(
|
|
365
|
-
`${method} ${
|
|
885
|
+
`${method} ${path2} -> ${res.status}: ${text.slice(0, 400)}`
|
|
366
886
|
);
|
|
367
887
|
}
|
|
368
888
|
return JSON.parse(text);
|
|
@@ -424,7 +944,7 @@ async function waitForRun(runId, opts = {}) {
|
|
|
424
944
|
);
|
|
425
945
|
opts.onTick?.(run);
|
|
426
946
|
await new Promise(
|
|
427
|
-
(
|
|
947
|
+
(resolve2) => setTimeout(resolve2, (opts.intervalSeconds ?? 20) * 1e3)
|
|
428
948
|
);
|
|
429
949
|
}
|
|
430
950
|
}
|
|
@@ -498,6 +1018,8 @@ var WorldTask, WorldSet;
|
|
|
498
1018
|
var init_worlds = __esm({
|
|
499
1019
|
"src/worlds/index.ts"() {
|
|
500
1020
|
init_session();
|
|
1021
|
+
init_hub();
|
|
1022
|
+
init_validate();
|
|
501
1023
|
WorldTask = class {
|
|
502
1024
|
constructor(world, name, variant) {
|
|
503
1025
|
this.world = world;
|
|
@@ -562,6 +1084,7 @@ var init_worlds = __esm({
|
|
|
562
1084
|
init_worlds();
|
|
563
1085
|
// Annotate the CommonJS export names for ESM import in node:
|
|
564
1086
|
0 && (module.exports = {
|
|
1087
|
+
DEFAULT_BRANCH,
|
|
565
1088
|
WorldSession,
|
|
566
1089
|
WorldSessionCallError,
|
|
567
1090
|
WorldSessionTimeout,
|
|
@@ -569,16 +1092,29 @@ init_worlds();
|
|
|
569
1092
|
WorldTask,
|
|
570
1093
|
apiRequest,
|
|
571
1094
|
attachSession,
|
|
1095
|
+
buildSourceTarball,
|
|
1096
|
+
collectArchiveRelPaths,
|
|
1097
|
+
computeContentHash,
|
|
1098
|
+
createRef,
|
|
572
1099
|
deleteEnvSecret,
|
|
573
1100
|
detectProvenance,
|
|
574
1101
|
getRun,
|
|
1102
|
+
isIncludedInContentHash,
|
|
575
1103
|
listEnvSecretKeys,
|
|
576
1104
|
listRunConfigs,
|
|
1105
|
+
localTreeState,
|
|
577
1106
|
openSession,
|
|
578
1107
|
openWorld,
|
|
1108
|
+
propose,
|
|
1109
|
+
pull,
|
|
1110
|
+
push,
|
|
1111
|
+
readLocalMeta,
|
|
579
1112
|
runSessions,
|
|
580
1113
|
schemaFromSignature,
|
|
581
1114
|
setEnvSecret,
|
|
582
|
-
|
|
1115
|
+
snapshotTreeHashes,
|
|
1116
|
+
validateWorld,
|
|
1117
|
+
waitForRun,
|
|
1118
|
+
writeLocalMeta
|
|
583
1119
|
});
|
|
584
1120
|
//# sourceMappingURL=index.js.map
|