@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/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;
|
|
@@ -21,6 +23,14 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
21
23
|
}
|
|
22
24
|
return to;
|
|
23
25
|
};
|
|
26
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
27
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
28
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
29
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
30
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
31
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
32
|
+
mod
|
|
33
|
+
));
|
|
24
34
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
25
35
|
|
|
26
36
|
// src/worlds/session.ts
|
|
@@ -318,9 +328,506 @@ var init_session = __esm({
|
|
|
318
328
|
}
|
|
319
329
|
});
|
|
320
330
|
|
|
331
|
+
// src/worlds/hub.ts
|
|
332
|
+
function isExcludedDirComponent(component) {
|
|
333
|
+
return component.startsWith(".") || ROOT_EXCLUDED_DIRS.has(component) || component.endsWith(".egg-info");
|
|
334
|
+
}
|
|
335
|
+
function isIncludedInContentHash(relPath, includeAllRootFiles) {
|
|
336
|
+
const parts = relPath.split("/");
|
|
337
|
+
const name = parts[parts.length - 1];
|
|
338
|
+
const dirParts = parts.slice(0, -1);
|
|
339
|
+
if (name.startsWith(".")) return false;
|
|
340
|
+
if (parts.includes("__pycache__")) return false;
|
|
341
|
+
if (dirParts.length === 0) {
|
|
342
|
+
return includeAllRootFiles || name === "README.md" || name === "pyproject.toml" || name === "gateway-env.toml" || name.endsWith(".py");
|
|
343
|
+
}
|
|
344
|
+
return !dirParts.some(isExcludedDirComponent);
|
|
345
|
+
}
|
|
346
|
+
function collectArchiveRelPaths(dir) {
|
|
347
|
+
if (fs.existsSync(path.join(dir, ".gitignore"))) {
|
|
348
|
+
throw new Error(
|
|
349
|
+
"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."
|
|
350
|
+
);
|
|
351
|
+
}
|
|
352
|
+
const out = [];
|
|
353
|
+
const includeAllRootFiles = fs.existsSync(path.join(dir, "gateway-env.toml"));
|
|
354
|
+
const walk = (rel) => {
|
|
355
|
+
const abs = rel ? path.join(dir, rel) : dir;
|
|
356
|
+
for (const entry of fs.readdirSync(abs, { withFileTypes: true }).sort((a, b) => a.name.localeCompare(b.name))) {
|
|
357
|
+
const childRel = rel ? `${rel}/${entry.name}` : entry.name;
|
|
358
|
+
if (entry.isDirectory()) {
|
|
359
|
+
if (!isExcludedDirComponent(entry.name)) walk(childRel);
|
|
360
|
+
} else if (entry.isFile()) {
|
|
361
|
+
if (isIncludedInContentHash(childRel, includeAllRootFiles)) {
|
|
362
|
+
out.push(childRel);
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
};
|
|
367
|
+
walk("");
|
|
368
|
+
return out.sort((a, b) => a < b ? -1 : a > b ? 1 : 0);
|
|
369
|
+
}
|
|
370
|
+
function computeContentHash(dir) {
|
|
371
|
+
const hasher = (0, import_node_crypto.createHash)("sha256");
|
|
372
|
+
for (const relPath of collectArchiveRelPaths(dir)) {
|
|
373
|
+
hasher.update(Buffer.from(`file:${relPath}`, "utf-8"));
|
|
374
|
+
hasher.update(fs.readFileSync(path.join(dir, relPath)));
|
|
375
|
+
}
|
|
376
|
+
return hasher.digest("hex");
|
|
377
|
+
}
|
|
378
|
+
function octal(value, length) {
|
|
379
|
+
return Buffer.from(value.toString(8).padStart(length - 1, "0") + "\0", "ascii");
|
|
380
|
+
}
|
|
381
|
+
function tarHeader(name, size) {
|
|
382
|
+
const header = Buffer.alloc(512);
|
|
383
|
+
header.write(name, 0, 100, "utf-8");
|
|
384
|
+
octal(420, 8).copy(header, 100);
|
|
385
|
+
octal(0, 8).copy(header, 108);
|
|
386
|
+
octal(0, 8).copy(header, 116);
|
|
387
|
+
octal(size, 12).copy(header, 124);
|
|
388
|
+
octal(0, 12).copy(header, 136);
|
|
389
|
+
header.write(" ", 148, "ascii");
|
|
390
|
+
header.write("0", 156, "ascii");
|
|
391
|
+
header.write("ustar", 257, "ascii");
|
|
392
|
+
header.write("00", 263, "ascii");
|
|
393
|
+
let sum = 0;
|
|
394
|
+
for (const byte of header) sum += byte;
|
|
395
|
+
header.write(sum.toString(8).padStart(6, "0") + "\0 ", 148, "ascii");
|
|
396
|
+
return header;
|
|
397
|
+
}
|
|
398
|
+
function tarMember(name, payload) {
|
|
399
|
+
const parts = [];
|
|
400
|
+
const nameBytes = Buffer.byteLength(name, "utf-8");
|
|
401
|
+
if (nameBytes > 100) {
|
|
402
|
+
const body = Buffer.from(name + "\0", "utf-8");
|
|
403
|
+
const lHeader = tarHeader("././@LongLink", body.length);
|
|
404
|
+
lHeader.write("L", 156, "ascii");
|
|
405
|
+
let sum = 0;
|
|
406
|
+
lHeader.write(" ", 148, "ascii");
|
|
407
|
+
for (const byte of lHeader) sum += byte;
|
|
408
|
+
lHeader.write(sum.toString(8).padStart(6, "0") + "\0 ", 148, "ascii");
|
|
409
|
+
parts.push(lHeader, body);
|
|
410
|
+
const pad2 = body.length % 512 === 0 ? 0 : 512 - body.length % 512;
|
|
411
|
+
if (pad2) parts.push(Buffer.alloc(pad2));
|
|
412
|
+
parts.push(tarHeader(name.slice(0, 100), payload.length));
|
|
413
|
+
} else {
|
|
414
|
+
parts.push(tarHeader(name, payload.length));
|
|
415
|
+
}
|
|
416
|
+
parts.push(payload);
|
|
417
|
+
const pad = payload.length % 512 === 0 ? 0 : 512 - payload.length % 512;
|
|
418
|
+
if (pad) parts.push(Buffer.alloc(pad));
|
|
419
|
+
return parts;
|
|
420
|
+
}
|
|
421
|
+
function buildSourceTarball(dir) {
|
|
422
|
+
const parts = [];
|
|
423
|
+
for (const relPath of collectArchiveRelPaths(dir)) {
|
|
424
|
+
parts.push(...tarMember(relPath, fs.readFileSync(path.join(dir, relPath))));
|
|
425
|
+
}
|
|
426
|
+
parts.push(Buffer.alloc(1024));
|
|
427
|
+
return (0, import_node_zlib.gzipSync)(Buffer.concat(parts), { level: 9 });
|
|
428
|
+
}
|
|
429
|
+
function readLocalMeta(dir) {
|
|
430
|
+
try {
|
|
431
|
+
const raw = fs.readFileSync(path.join(dir, META_RELPATH), "utf-8");
|
|
432
|
+
const parsed = JSON.parse(raw);
|
|
433
|
+
return parsed && typeof parsed === "object" ? parsed : null;
|
|
434
|
+
} catch {
|
|
435
|
+
return null;
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
function writeLocalMeta(dir, meta) {
|
|
439
|
+
fs.mkdirSync(path.join(dir, ".gateway"), { recursive: true });
|
|
440
|
+
fs.writeFileSync(path.join(dir, META_RELPATH), JSON.stringify(meta, null, 2));
|
|
441
|
+
}
|
|
442
|
+
function snapshotTreeHashes(dir) {
|
|
443
|
+
const out = {};
|
|
444
|
+
for (const relPath of collectArchiveRelPaths(dir)) {
|
|
445
|
+
out[relPath] = (0, import_node_crypto.createHash)("sha256").update(fs.readFileSync(path.join(dir, relPath))).digest("hex");
|
|
446
|
+
}
|
|
447
|
+
return out;
|
|
448
|
+
}
|
|
449
|
+
function localTreeState(dir) {
|
|
450
|
+
const meta = readLocalMeta(dir);
|
|
451
|
+
const base = meta?.baseFiles;
|
|
452
|
+
if (!base || typeof base !== "object") {
|
|
453
|
+
return { meta, dirty: [], clean: false };
|
|
454
|
+
}
|
|
455
|
+
const now = snapshotTreeHashes(dir);
|
|
456
|
+
const dirty = /* @__PURE__ */ new Set();
|
|
457
|
+
for (const [p, h] of Object.entries(now)) if (base[p] !== h) dirty.add(p);
|
|
458
|
+
for (const p of Object.keys(base)) if (!(p in now)) dirty.add(p);
|
|
459
|
+
return { meta, dirty: [...dirty].sort(), clean: dirty.size === 0 };
|
|
460
|
+
}
|
|
461
|
+
function readPyproject(dir) {
|
|
462
|
+
try {
|
|
463
|
+
const text = fs.readFileSync(path.join(dir, "pyproject.toml"), "utf-8");
|
|
464
|
+
const section = /\[project\]([\s\S]*?)(\n\[|$)/.exec(text)?.[1] ?? "";
|
|
465
|
+
const name = /\bname\s*=\s*"([^"]+)"/.exec(section)?.[1];
|
|
466
|
+
const version = /\bversion\s*=\s*"([^"]+)"/.exec(section)?.[1];
|
|
467
|
+
return { name, version };
|
|
468
|
+
} catch {
|
|
469
|
+
return {};
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
function buildFileManifest(dir) {
|
|
473
|
+
const entries = [];
|
|
474
|
+
const walk = (rel) => {
|
|
475
|
+
const abs = rel ? path.join(dir, rel) : dir;
|
|
476
|
+
for (const entry of fs.readdirSync(abs, { withFileTypes: true }).sort((a, b) => a.name.localeCompare(b.name))) {
|
|
477
|
+
const childRel = rel ? `${rel}/${entry.name}` : entry.name;
|
|
478
|
+
if (entry.isDirectory()) {
|
|
479
|
+
if (!SKIP_DIRS.has(entry.name) && !entry.name.endsWith(".egg-info")) {
|
|
480
|
+
walk(childRel);
|
|
481
|
+
}
|
|
482
|
+
} else if (entry.isFile()) {
|
|
483
|
+
const payload = fs.readFileSync(path.join(dir, childRel));
|
|
484
|
+
entries.push({
|
|
485
|
+
path: childRel,
|
|
486
|
+
isDirectory: false,
|
|
487
|
+
size: payload.length,
|
|
488
|
+
sha256: (0, import_node_crypto.createHash)("sha256").update(payload).digest("hex")
|
|
489
|
+
});
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
};
|
|
493
|
+
walk("");
|
|
494
|
+
return entries;
|
|
495
|
+
}
|
|
496
|
+
async function putObject(url, data, shaB64) {
|
|
497
|
+
const resp = await fetch(url, {
|
|
498
|
+
method: "PUT",
|
|
499
|
+
headers: {
|
|
500
|
+
"Content-Type": "application/gzip",
|
|
501
|
+
"x-amz-checksum-sha256": shaB64
|
|
502
|
+
},
|
|
503
|
+
body: new Uint8Array(data)
|
|
504
|
+
});
|
|
505
|
+
if (!resp.ok) {
|
|
506
|
+
throw new Error(`object PUT -> ${resp.status}: ${(await resp.text()).slice(0, 300)}`);
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
async function push(dir, opts = {}) {
|
|
510
|
+
const options = opts.options ?? {};
|
|
511
|
+
if (!fs.statSync(dir).isDirectory()) throw new Error(`Not a directory: ${dir}`);
|
|
512
|
+
const localMeta = readLocalMeta(dir) ?? {};
|
|
513
|
+
const branch = opts.branch ?? localMeta.branch ?? DEFAULT_BRANCH;
|
|
514
|
+
const baseVersionId = localMeta.versionId ?? null;
|
|
515
|
+
const contentHash = computeContentHash(dir);
|
|
516
|
+
const pyproject = readPyproject(dir);
|
|
517
|
+
const slug = opts.slug ?? pyproject.name ?? path.basename(path.resolve(dir));
|
|
518
|
+
const resolve2 = await apiRequest(
|
|
519
|
+
options,
|
|
520
|
+
"POST",
|
|
521
|
+
"/api/public/benchmark-containers/resolve",
|
|
522
|
+
{ slug, name: pyproject.name ?? slug }
|
|
523
|
+
);
|
|
524
|
+
const tarball = buildSourceTarball(dir);
|
|
525
|
+
const bundleSha256 = sha256b64(tarball);
|
|
526
|
+
const version = await apiRequest(options, "POST", "/api/public/benchmark-containers/versions", {
|
|
527
|
+
containerId: resolve2.containerId,
|
|
528
|
+
contentHash,
|
|
529
|
+
bundleSha256,
|
|
530
|
+
bundleSizeBytes: tarball.length,
|
|
531
|
+
...pyproject.version ? { semanticVersion: pyproject.version } : {},
|
|
532
|
+
pyprojectMeta: pyproject,
|
|
533
|
+
fileManifest: buildFileManifest(dir),
|
|
534
|
+
branch,
|
|
535
|
+
baseVersionId,
|
|
536
|
+
...opts.force ? { force: true } : {},
|
|
537
|
+
...opts.message ? { changeReason: opts.message } : {},
|
|
538
|
+
...opts.author ? { author: opts.author } : {}
|
|
539
|
+
});
|
|
540
|
+
if (version.uploadUrl) await putObject(version.uploadUrl, tarball, bundleSha256);
|
|
541
|
+
await apiRequest(
|
|
542
|
+
options,
|
|
543
|
+
"POST",
|
|
544
|
+
`/api/public/benchmark-containers/versions/${version.versionId}/finalize`,
|
|
545
|
+
{ branch, baseVersionId, ...opts.force ? { force: true } : {} }
|
|
546
|
+
);
|
|
547
|
+
writeLocalMeta(dir, {
|
|
548
|
+
...localMeta,
|
|
549
|
+
slug,
|
|
550
|
+
ref: branch,
|
|
551
|
+
branch,
|
|
552
|
+
versionId: version.versionId,
|
|
553
|
+
contentHash,
|
|
554
|
+
semanticVersion: pyproject.version,
|
|
555
|
+
forkedFromVersionId: baseVersionId,
|
|
556
|
+
baseFiles: snapshotTreeHashes(dir)
|
|
557
|
+
});
|
|
558
|
+
return { slug, versionId: version.versionId, contentHash, branch };
|
|
559
|
+
}
|
|
560
|
+
function extractBundle(bundle, dir) {
|
|
561
|
+
const tar = (0, import_node_zlib.gunzipSync)(bundle);
|
|
562
|
+
let offset = 0;
|
|
563
|
+
let longName = null;
|
|
564
|
+
let written = 0;
|
|
565
|
+
while (offset + 512 <= tar.length) {
|
|
566
|
+
const header = tar.subarray(offset, offset + 512);
|
|
567
|
+
offset += 512;
|
|
568
|
+
if (header.every((b) => b === 0)) break;
|
|
569
|
+
const rawName = header.subarray(0, 100).toString("utf-8").replace(/\0.*$/, "");
|
|
570
|
+
const size = parseInt(header.subarray(124, 136).toString("ascii").replace(/\0.*$/, "").trim(), 8) || 0;
|
|
571
|
+
const typeflag = header.subarray(156, 157).toString("ascii");
|
|
572
|
+
const body = tar.subarray(offset, offset + size);
|
|
573
|
+
offset += size + (size % 512 === 0 ? 0 : 512 - size % 512);
|
|
574
|
+
if (typeflag === "L") {
|
|
575
|
+
longName = body.toString("utf-8").replace(/\0.*$/, "");
|
|
576
|
+
continue;
|
|
577
|
+
}
|
|
578
|
+
const name = (longName ?? rawName).replace(/^\.\//, "");
|
|
579
|
+
longName = null;
|
|
580
|
+
if (typeflag !== "0" && typeflag !== "") continue;
|
|
581
|
+
if (name.startsWith("/") || name.split("/").includes("..")) continue;
|
|
582
|
+
const target = path.join(dir, name);
|
|
583
|
+
fs.mkdirSync(path.dirname(target), { recursive: true });
|
|
584
|
+
fs.writeFileSync(target, body);
|
|
585
|
+
written++;
|
|
586
|
+
}
|
|
587
|
+
return written;
|
|
588
|
+
}
|
|
589
|
+
async function pull(slugRef, target, options = {}) {
|
|
590
|
+
const at = slugRef.indexOf("@");
|
|
591
|
+
const slug = at === -1 ? slugRef : slugRef.slice(0, at);
|
|
592
|
+
const ref = at === -1 ? "latest" : slugRef.slice(at + 1);
|
|
593
|
+
const details = await apiRequest(options, "POST", "/api/public/benchmark-containers/resolve-version", {
|
|
594
|
+
slug,
|
|
595
|
+
ref
|
|
596
|
+
});
|
|
597
|
+
if (!details.downloadUrl) {
|
|
598
|
+
throw new Error(`${slug}@${ref} resolved but has no uploaded bundle`);
|
|
599
|
+
}
|
|
600
|
+
let dir = target ?? path.join(process.cwd(), slug);
|
|
601
|
+
if (!target) {
|
|
602
|
+
let i = 1;
|
|
603
|
+
const base = dir;
|
|
604
|
+
while (fs.existsSync(dir)) dir = `${base}-${i++}`;
|
|
605
|
+
}
|
|
606
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
607
|
+
const resp = await fetch(details.downloadUrl);
|
|
608
|
+
if (!resp.ok) throw new Error(`bundle download -> ${resp.status}`);
|
|
609
|
+
const bundle = Buffer.from(await resp.arrayBuffer());
|
|
610
|
+
if (details.bundleSha256 && sha256b64(bundle) !== details.bundleSha256) {
|
|
611
|
+
throw new Error(
|
|
612
|
+
`bundle integrity check failed for ${slug}@${ref}: downloaded sha256 != recorded bundleSha256`
|
|
613
|
+
);
|
|
614
|
+
}
|
|
615
|
+
const files = extractBundle(bundle, dir);
|
|
616
|
+
const branch = ref === "latest" || /^\d|^[0-9a-f]{8,}$/.test(ref) ? DEFAULT_BRANCH : ref;
|
|
617
|
+
writeLocalMeta(dir, {
|
|
618
|
+
slug,
|
|
619
|
+
ref,
|
|
620
|
+
branch,
|
|
621
|
+
versionId: details.versionId,
|
|
622
|
+
contentHash: details.contentHash,
|
|
623
|
+
semanticVersion: details.semanticVersion ?? void 0,
|
|
624
|
+
baseFiles: snapshotTreeHashes(dir)
|
|
625
|
+
});
|
|
626
|
+
return { slug, dir, versionId: details.versionId, files };
|
|
627
|
+
}
|
|
628
|
+
async function propose(dir, opts) {
|
|
629
|
+
const meta = readLocalMeta(dir);
|
|
630
|
+
if (!meta?.slug || !meta.baseFiles) {
|
|
631
|
+
throw new Error("This dir has no pull/push base \u2014 run pull first, then edit, then propose.");
|
|
632
|
+
}
|
|
633
|
+
const state2 = localTreeState(dir);
|
|
634
|
+
if (state2.clean) throw new Error("Nothing to propose \u2014 the tree matches its base.");
|
|
635
|
+
const changes = state2.dirty.map((relPath) => {
|
|
636
|
+
const abs = path.join(dir, relPath);
|
|
637
|
+
if (!fs.existsSync(abs)) return { path: relPath, action: "delete" };
|
|
638
|
+
return {
|
|
639
|
+
path: relPath,
|
|
640
|
+
action: "write",
|
|
641
|
+
newContent: fs.readFileSync(abs, "utf-8")
|
|
642
|
+
};
|
|
643
|
+
});
|
|
644
|
+
const res = await apiRequest(
|
|
645
|
+
opts.options ?? {},
|
|
646
|
+
"POST",
|
|
647
|
+
"/api/public/benchmark-containers/proposals",
|
|
648
|
+
{
|
|
649
|
+
slug: meta.slug,
|
|
650
|
+
title: opts.title,
|
|
651
|
+
changeReason: opts.reason,
|
|
652
|
+
baseVersionId: meta.versionId,
|
|
653
|
+
...opts.targetBranch ? { targetBranch: opts.targetBranch } : {},
|
|
654
|
+
changes
|
|
655
|
+
}
|
|
656
|
+
);
|
|
657
|
+
return res;
|
|
658
|
+
}
|
|
659
|
+
async function createRef(slug, name, kind, versionId, options = {}) {
|
|
660
|
+
return apiRequest(options, "POST", "/api/public/benchmark-containers/refs", {
|
|
661
|
+
slug,
|
|
662
|
+
name,
|
|
663
|
+
kind,
|
|
664
|
+
...versionId ? { versionId } : {}
|
|
665
|
+
});
|
|
666
|
+
}
|
|
667
|
+
var import_node_crypto, import_node_zlib, fs, path, DEFAULT_BRANCH, META_RELPATH, SKIP_DIRS, ROOT_EXCLUDED_DIRS, sha256b64;
|
|
668
|
+
var init_hub = __esm({
|
|
669
|
+
"src/worlds/hub.ts"() {
|
|
670
|
+
"use strict";
|
|
671
|
+
import_node_crypto = require("crypto");
|
|
672
|
+
import_node_zlib = require("zlib");
|
|
673
|
+
fs = __toESM(require("fs"));
|
|
674
|
+
path = __toESM(require("path"));
|
|
675
|
+
init_worlds();
|
|
676
|
+
DEFAULT_BRANCH = "main";
|
|
677
|
+
META_RELPATH = path.join(".gateway", ".env-metadata.json");
|
|
678
|
+
SKIP_DIRS = /* @__PURE__ */ new Set([
|
|
679
|
+
".git",
|
|
680
|
+
"__pycache__",
|
|
681
|
+
"node_modules",
|
|
682
|
+
".venv",
|
|
683
|
+
".mypy_cache",
|
|
684
|
+
"dist",
|
|
685
|
+
"build",
|
|
686
|
+
"outputs"
|
|
687
|
+
]);
|
|
688
|
+
ROOT_EXCLUDED_DIRS = /* @__PURE__ */ new Set(["dist", "build", "outputs", "__pycache__"]);
|
|
689
|
+
sha256b64 = (data) => (0, import_node_crypto.createHash)("sha256").update(data).digest("base64");
|
|
690
|
+
}
|
|
691
|
+
});
|
|
692
|
+
|
|
693
|
+
// src/worlds/validate.ts
|
|
694
|
+
function fmtScore(score) {
|
|
695
|
+
return score === null ? "no score" : score.toFixed(3);
|
|
696
|
+
}
|
|
697
|
+
function buildMarkdown(report, minScore) {
|
|
698
|
+
const lines = [];
|
|
699
|
+
lines.push(
|
|
700
|
+
`### World validation ${report.ok ? "passed" : "failed"} \u2014 \`${report.slug}@${report.branch}\``
|
|
701
|
+
);
|
|
702
|
+
lines.push("");
|
|
703
|
+
lines.push(
|
|
704
|
+
`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}.` : ".")
|
|
705
|
+
);
|
|
706
|
+
lines.push("");
|
|
707
|
+
lines.push("| Model | Status | Score | Run |");
|
|
708
|
+
lines.push("| --- | --- | ---: | --- |");
|
|
709
|
+
for (const run of report.runs) {
|
|
710
|
+
const r = run.report;
|
|
711
|
+
const link = r?.url ? `[open](${r.url})` : "\u2014";
|
|
712
|
+
const status = run.failure ? `\u274C ${run.failure}` : `\u2705 ${r?.status ?? "COMPLETED"}`;
|
|
713
|
+
lines.push(
|
|
714
|
+
`| \`${run.model}\` | ${status} | ${fmtScore(r?.score ?? null)} | ${link} |`
|
|
715
|
+
);
|
|
716
|
+
}
|
|
717
|
+
const taskRows = report.runs.flatMap(
|
|
718
|
+
(run) => (run.report?.samples ?? []).map((sample) => ({
|
|
719
|
+
model: run.model,
|
|
720
|
+
task: sample.task ?? "?",
|
|
721
|
+
reward: sample.reward
|
|
722
|
+
}))
|
|
723
|
+
);
|
|
724
|
+
if (taskRows.length > 0 && taskRows.length <= 40) {
|
|
725
|
+
lines.push("");
|
|
726
|
+
lines.push("<details><summary>Per-task rewards</summary>");
|
|
727
|
+
lines.push("");
|
|
728
|
+
lines.push("| Task | Model | Reward |");
|
|
729
|
+
lines.push("| --- | --- | ---: |");
|
|
730
|
+
for (const row of taskRows) {
|
|
731
|
+
lines.push(
|
|
732
|
+
`| ${row.task} | \`${row.model}\` | ${row.reward === null ? "no score" : row.reward.toFixed(2)} |`
|
|
733
|
+
);
|
|
734
|
+
}
|
|
735
|
+
lines.push("");
|
|
736
|
+
lines.push("</details>");
|
|
737
|
+
}
|
|
738
|
+
return lines.join("\n");
|
|
739
|
+
}
|
|
740
|
+
async function validateWorld(dir, opts) {
|
|
741
|
+
const options = opts.options ?? {};
|
|
742
|
+
const progress = opts.onProgress ?? (() => {
|
|
743
|
+
});
|
|
744
|
+
const minScore = opts.minScore ?? null;
|
|
745
|
+
const provenance = detectProvenance();
|
|
746
|
+
const branch = opts.branch ?? provenance.branch;
|
|
747
|
+
if (!branch)
|
|
748
|
+
throw new Error(
|
|
749
|
+
"No branch to validate on: pass --branch or run inside a git checkout / GitHub Actions."
|
|
750
|
+
);
|
|
751
|
+
progress(`pushing ${dir} as ${opts.slug ?? "(pyproject name)"}@${branch}\u2026`);
|
|
752
|
+
const pushed = await push(dir, {
|
|
753
|
+
slug: opts.slug,
|
|
754
|
+
branch,
|
|
755
|
+
message: `PR validation push (${provenance.commit?.slice(0, 12) ?? "local"})`,
|
|
756
|
+
...provenance.actor?.name ? { author: provenance.actor.name } : {},
|
|
757
|
+
options
|
|
758
|
+
});
|
|
759
|
+
progress(`pushed version ${pushed.versionId} (${pushed.contentHash.slice(0, 12)})`);
|
|
760
|
+
const configs = await listRunConfigs(options);
|
|
761
|
+
const runConfig = configs.find((c) => c.id === opts.runConfig) ?? configs.find((c) => c.name === opts.runConfig);
|
|
762
|
+
if (!runConfig) {
|
|
763
|
+
const known = configs.map((c) => c.name).join(", ") || "(none)";
|
|
764
|
+
throw new Error(
|
|
765
|
+
`Run config "${opts.runConfig}" not found in this project. Have: ${known}`
|
|
766
|
+
);
|
|
767
|
+
}
|
|
768
|
+
progress(`dispatching run config "${runConfig.name}" (${runConfig.models.join(", ")})\u2026`);
|
|
769
|
+
const dispatched = await apiRequest(options, "POST", "/api/public/benchmark-containers/run-configs/dispatch", {
|
|
770
|
+
runConfigId: runConfig.id,
|
|
771
|
+
versionId: pushed.versionId,
|
|
772
|
+
...provenance
|
|
773
|
+
});
|
|
774
|
+
const runs = [];
|
|
775
|
+
for (const run of dispatched.runs) {
|
|
776
|
+
if (!run.ok) {
|
|
777
|
+
runs.push({
|
|
778
|
+
model: run.model,
|
|
779
|
+
runId: run.runId,
|
|
780
|
+
report: null,
|
|
781
|
+
failure: `dispatch failed: ${run.error ?? "unknown error"}`
|
|
782
|
+
});
|
|
783
|
+
continue;
|
|
784
|
+
}
|
|
785
|
+
progress(`waiting on ${run.model} (run ${run.runId})\u2026`);
|
|
786
|
+
let report = null;
|
|
787
|
+
let failure = null;
|
|
788
|
+
try {
|
|
789
|
+
report = await waitForRun(run.runId, {
|
|
790
|
+
timeoutMinutes: opts.timeoutMinutes ?? 45,
|
|
791
|
+
options,
|
|
792
|
+
onTick: (r) => progress(
|
|
793
|
+
`\u2026${run.model}: ${r.status.toLowerCase()} (${r.shardsCompleted ?? 0}/${r.parallelism} shards)`
|
|
794
|
+
)
|
|
795
|
+
});
|
|
796
|
+
if (report.status.toUpperCase() !== "COMPLETED") {
|
|
797
|
+
failure = report.status;
|
|
798
|
+
} else if (minScore !== null) {
|
|
799
|
+
if (report.score === null) failure = "completed without a score";
|
|
800
|
+
else if (report.score < minScore)
|
|
801
|
+
failure = `score ${fmtScore(report.score)} < ${minScore}`;
|
|
802
|
+
}
|
|
803
|
+
} catch (error) {
|
|
804
|
+
failure = error instanceof Error ? error.message : String(error);
|
|
805
|
+
}
|
|
806
|
+
runs.push({ model: run.model, runId: run.runId, report, failure });
|
|
807
|
+
}
|
|
808
|
+
const base = {
|
|
809
|
+
ok: runs.length > 0 && runs.every((r) => r.failure === null),
|
|
810
|
+
slug: pushed.slug,
|
|
811
|
+
branch,
|
|
812
|
+
versionId: pushed.versionId,
|
|
813
|
+
contentHash: pushed.contentHash,
|
|
814
|
+
runConfig: { id: runConfig.id, name: runConfig.name },
|
|
815
|
+
runs
|
|
816
|
+
};
|
|
817
|
+
return { ...base, markdown: buildMarkdown(base, minScore) };
|
|
818
|
+
}
|
|
819
|
+
var init_validate = __esm({
|
|
820
|
+
"src/worlds/validate.ts"() {
|
|
821
|
+
"use strict";
|
|
822
|
+
init_worlds();
|
|
823
|
+
init_hub();
|
|
824
|
+
}
|
|
825
|
+
});
|
|
826
|
+
|
|
321
827
|
// src/worlds/index.ts
|
|
322
828
|
var worlds_exports = {};
|
|
323
829
|
__export(worlds_exports, {
|
|
830
|
+
DEFAULT_BRANCH: () => DEFAULT_BRANCH,
|
|
324
831
|
WorldSession: () => WorldSession,
|
|
325
832
|
WorldSessionCallError: () => WorldSessionCallError,
|
|
326
833
|
WorldSessionTimeout: () => WorldSessionTimeout,
|
|
@@ -328,17 +835,30 @@ __export(worlds_exports, {
|
|
|
328
835
|
WorldTask: () => WorldTask,
|
|
329
836
|
apiRequest: () => apiRequest,
|
|
330
837
|
attachSession: () => attachSession,
|
|
838
|
+
buildSourceTarball: () => buildSourceTarball,
|
|
839
|
+
collectArchiveRelPaths: () => collectArchiveRelPaths,
|
|
840
|
+
computeContentHash: () => computeContentHash,
|
|
841
|
+
createRef: () => createRef,
|
|
331
842
|
deleteEnvSecret: () => deleteEnvSecret,
|
|
332
843
|
detectProvenance: () => detectProvenance,
|
|
333
844
|
getRun: () => getRun,
|
|
845
|
+
isIncludedInContentHash: () => isIncludedInContentHash,
|
|
334
846
|
listEnvSecretKeys: () => listEnvSecretKeys,
|
|
335
847
|
listRunConfigs: () => listRunConfigs,
|
|
848
|
+
localTreeState: () => localTreeState,
|
|
336
849
|
openSession: () => openSession,
|
|
337
850
|
openWorld: () => openWorld,
|
|
851
|
+
propose: () => propose,
|
|
852
|
+
pull: () => pull,
|
|
853
|
+
push: () => push,
|
|
854
|
+
readLocalMeta: () => readLocalMeta,
|
|
338
855
|
runSessions: () => runSessions,
|
|
339
856
|
schemaFromSignature: () => schemaFromSignature,
|
|
340
857
|
setEnvSecret: () => setEnvSecret,
|
|
341
|
-
|
|
858
|
+
snapshotTreeHashes: () => snapshotTreeHashes,
|
|
859
|
+
validateWorld: () => validateWorld,
|
|
860
|
+
waitForRun: () => waitForRun,
|
|
861
|
+
writeLocalMeta: () => writeLocalMeta
|
|
342
862
|
});
|
|
343
863
|
function resolveEnv(options) {
|
|
344
864
|
const host = options.host ?? process.env.GATEWAY_HOST ?? "https://withgateway.ai";
|
|
@@ -351,9 +871,9 @@ function resolveEnv(options) {
|
|
|
351
871
|
}
|
|
352
872
|
return { host: host.replace(/\/+$/, ""), publicKey, secretKey };
|
|
353
873
|
}
|
|
354
|
-
async function apiRequest(options, method,
|
|
874
|
+
async function apiRequest(options, method, path2, body) {
|
|
355
875
|
const { host, publicKey, secretKey } = resolveEnv(options);
|
|
356
|
-
const res = await fetch(`${host}${
|
|
876
|
+
const res = await fetch(`${host}${path2}`, {
|
|
357
877
|
method,
|
|
358
878
|
headers: {
|
|
359
879
|
"content-type": "application/json",
|
|
@@ -364,7 +884,7 @@ async function apiRequest(options, method, path, body) {
|
|
|
364
884
|
const text = await res.text();
|
|
365
885
|
if (!res.ok) {
|
|
366
886
|
throw new Error(
|
|
367
|
-
`${method} ${
|
|
887
|
+
`${method} ${path2} -> ${res.status}: ${text.slice(0, 400)}`
|
|
368
888
|
);
|
|
369
889
|
}
|
|
370
890
|
return JSON.parse(text);
|
|
@@ -426,7 +946,7 @@ async function waitForRun(runId, opts = {}) {
|
|
|
426
946
|
);
|
|
427
947
|
opts.onTick?.(run);
|
|
428
948
|
await new Promise(
|
|
429
|
-
(
|
|
949
|
+
(resolve2) => setTimeout(resolve2, (opts.intervalSeconds ?? 20) * 1e3)
|
|
430
950
|
);
|
|
431
951
|
}
|
|
432
952
|
}
|
|
@@ -501,6 +1021,8 @@ var init_worlds = __esm({
|
|
|
501
1021
|
"src/worlds/index.ts"() {
|
|
502
1022
|
"use strict";
|
|
503
1023
|
init_session();
|
|
1024
|
+
init_hub();
|
|
1025
|
+
init_validate();
|
|
504
1026
|
WorldTask = class {
|
|
505
1027
|
constructor(world, name, variant) {
|
|
506
1028
|
this.world = world;
|
|
@@ -568,7 +1090,7 @@ var require_package = __commonJS({
|
|
|
568
1090
|
"package.json"(exports2, module2) {
|
|
569
1091
|
module2.exports = {
|
|
570
1092
|
name: "@withgateway/sdk",
|
|
571
|
-
version: "0.1.
|
|
1093
|
+
version: "0.1.16",
|
|
572
1094
|
description: "Gateway SDK for TypeScript - A/B experiments, tracing, and observability",
|
|
573
1095
|
main: "./dist/index.js",
|
|
574
1096
|
module: "./dist/index.mjs",
|
|
@@ -739,6 +1261,7 @@ var require_package = __commonJS({
|
|
|
739
1261
|
var src_exports = {};
|
|
740
1262
|
__export(src_exports, {
|
|
741
1263
|
AGENT_ID_KEY: () => AGENT_ID_KEY,
|
|
1264
|
+
DEFAULT_BRANCH: () => DEFAULT_BRANCH,
|
|
742
1265
|
DEFAULT_TIMEOUT_SECONDS: () => DEFAULT_TIMEOUT_SECONDS,
|
|
743
1266
|
DriftError: () => DriftError,
|
|
744
1267
|
ENV_GATEWAY_HOST: () => ENV_GATEWAY_HOST,
|
|
@@ -791,11 +1314,15 @@ __export(src_exports, {
|
|
|
791
1314
|
assignVariant: () => assignVariant,
|
|
792
1315
|
attachSession: () => attachSession,
|
|
793
1316
|
basicAuthHeader: () => basicAuthHeader,
|
|
1317
|
+
buildSourceTarball: () => buildSourceTarball,
|
|
794
1318
|
canonicalJson: () => canonicalJson,
|
|
795
1319
|
clearExperimentContext: () => clearExperimentContext,
|
|
1320
|
+
collectArchiveRelPaths: () => collectArchiveRelPaths,
|
|
796
1321
|
computeBuildHash: () => computeBuildHash,
|
|
1322
|
+
computeContentHash: () => computeContentHash,
|
|
797
1323
|
computeHash: () => computeHash,
|
|
798
1324
|
context: () => context,
|
|
1325
|
+
createRef: () => createRef,
|
|
799
1326
|
currentTraceId: () => currentTraceId,
|
|
800
1327
|
defineTool: () => defineTool,
|
|
801
1328
|
deleteEnvSecret: () => deleteEnvSecret,
|
|
@@ -810,13 +1337,19 @@ __export(src_exports, {
|
|
|
810
1337
|
getRegisteredTools: () => getRegisteredTools,
|
|
811
1338
|
getRun: () => getRun,
|
|
812
1339
|
identify: () => identify,
|
|
1340
|
+
isIncludedInContentHash: () => isIncludedInContentHash,
|
|
813
1341
|
listEnvSecretKeys: () => listEnvSecretKeys,
|
|
814
1342
|
listRunConfigs: () => listRunConfigs,
|
|
815
1343
|
loadSession: () => loadSession,
|
|
1344
|
+
localTreeState: () => localTreeState,
|
|
816
1345
|
memory: () => memory,
|
|
817
1346
|
openSession: () => openSession,
|
|
818
1347
|
openWorld: () => openWorld,
|
|
819
1348
|
personas: () => personas,
|
|
1349
|
+
propose: () => propose,
|
|
1350
|
+
pull: () => pull,
|
|
1351
|
+
push: () => push,
|
|
1352
|
+
readLocalMeta: () => readLocalMeta,
|
|
820
1353
|
registerArtifact: () => registerArtifact,
|
|
821
1354
|
registerPrompt: () => registerPrompt,
|
|
822
1355
|
registerSkill: () => registerSkill,
|
|
@@ -833,11 +1366,14 @@ __export(src_exports, {
|
|
|
833
1366
|
sessions: () => sessions,
|
|
834
1367
|
setEnvSecret: () => setEnvSecret,
|
|
835
1368
|
setExperimentContext: () => setExperimentContext,
|
|
1369
|
+
snapshotTreeHashes: () => snapshotTreeHashes,
|
|
836
1370
|
success: () => success,
|
|
837
1371
|
suite: () => suite,
|
|
838
1372
|
tracing: () => tracing,
|
|
839
1373
|
users: () => users,
|
|
840
|
-
|
|
1374
|
+
validateWorld: () => validateWorld,
|
|
1375
|
+
waitForRun: () => waitForRun,
|
|
1376
|
+
writeLocalMeta: () => writeLocalMeta
|
|
841
1377
|
});
|
|
842
1378
|
module.exports = __toCommonJS(src_exports);
|
|
843
1379
|
|
|
@@ -1411,8 +1947,8 @@ var GatewayContext = class _GatewayContext {
|
|
|
1411
1947
|
}
|
|
1412
1948
|
return resolved;
|
|
1413
1949
|
}
|
|
1414
|
-
async requestJson(method,
|
|
1415
|
-
const response = await fetch(`${this.host}${
|
|
1950
|
+
async requestJson(method, path2, payload) {
|
|
1951
|
+
const response = await fetch(`${this.host}${path2}`, {
|
|
1416
1952
|
method,
|
|
1417
1953
|
headers: {
|
|
1418
1954
|
Authorization: this.authHeader(),
|
|
@@ -1423,7 +1959,7 @@ var GatewayContext = class _GatewayContext {
|
|
|
1423
1959
|
const text = await response.text();
|
|
1424
1960
|
const body = text ? safeJson(text) : {};
|
|
1425
1961
|
if (!response.ok) {
|
|
1426
|
-
const message = typeof body.message === "string" ? body.message : `Gateway API ${response.status} on ${
|
|
1962
|
+
const message = typeof body.message === "string" ? body.message : `Gateway API ${response.status} on ${path2}`;
|
|
1427
1963
|
if (response.status === 409) {
|
|
1428
1964
|
throw new GatewayContextConflictError(
|
|
1429
1965
|
message,
|
|
@@ -1432,7 +1968,7 @@ var GatewayContext = class _GatewayContext {
|
|
|
1432
1968
|
}
|
|
1433
1969
|
throw new GatewayContextError(message);
|
|
1434
1970
|
}
|
|
1435
|
-
this.log("%s %s -> %s", method,
|
|
1971
|
+
this.log("%s %s -> %s", method, path2, response.status);
|
|
1436
1972
|
return body;
|
|
1437
1973
|
}
|
|
1438
1974
|
authHeader() {
|
|
@@ -1539,11 +2075,11 @@ function primaryPathForKind(kind, snapshot) {
|
|
|
1539
2075
|
const preferred = kind === "agent" ? "AGENTS.md" : kind === "prompt" ? "PROMPT.md" : kind === "skill" ? "SKILL.md" : "MEMORY.md";
|
|
1540
2076
|
if (readFile(snapshot, preferred)) return preferred;
|
|
1541
2077
|
return Object.entries(snapshot.files).find(
|
|
1542
|
-
([
|
|
2078
|
+
([path2, entry]) => entry.type === "file" && path2.endsWith(".md")
|
|
1543
2079
|
)?.[0] ?? null;
|
|
1544
2080
|
}
|
|
1545
|
-
function parseJsonFile(snapshot,
|
|
1546
|
-
const content = readFile(snapshot,
|
|
2081
|
+
function parseJsonFile(snapshot, path2) {
|
|
2082
|
+
const content = readFile(snapshot, path2);
|
|
1547
2083
|
if (!content) return {};
|
|
1548
2084
|
try {
|
|
1549
2085
|
const parsed = JSON.parse(content);
|
|
@@ -1552,8 +2088,8 @@ function parseJsonFile(snapshot, path) {
|
|
|
1552
2088
|
return {};
|
|
1553
2089
|
}
|
|
1554
2090
|
}
|
|
1555
|
-
function readFile(snapshot,
|
|
1556
|
-
const entry = snapshot.files[
|
|
2091
|
+
function readFile(snapshot, path2) {
|
|
2092
|
+
const entry = snapshot.files[path2];
|
|
1557
2093
|
return entry?.type === "file" ? entry.content : null;
|
|
1558
2094
|
}
|
|
1559
2095
|
function provenanceFor(snapshot, label) {
|
|
@@ -1655,16 +2191,16 @@ var GatewayMemory = class _GatewayMemory {
|
|
|
1655
2191
|
`/api/public/context/memory/${encodeIdentifier2(identifier)}${suffix}`
|
|
1656
2192
|
);
|
|
1657
2193
|
}
|
|
1658
|
-
async read(target,
|
|
2194
|
+
async read(target, path2, options = {}) {
|
|
1659
2195
|
const snapshot = typeof target === "string" ? await this.pull(target, options) : target;
|
|
1660
|
-
const file = snapshot.files[
|
|
2196
|
+
const file = snapshot.files[path2];
|
|
1661
2197
|
return file?.type === "file" ? file.content : null;
|
|
1662
2198
|
}
|
|
1663
|
-
async write(target,
|
|
2199
|
+
async write(target, path2, content, options = {}) {
|
|
1664
2200
|
const snapshot = typeof target === "string" ? await this.pull(target) : target;
|
|
1665
2201
|
return this.push(snapshot.repo.repoHandle, {
|
|
1666
2202
|
files: {
|
|
1667
|
-
[
|
|
2203
|
+
[path2]: {
|
|
1668
2204
|
content,
|
|
1669
2205
|
...options.mimeType ? { mimeType: options.mimeType } : {}
|
|
1670
2206
|
}
|
|
@@ -1674,10 +2210,10 @@ var GatewayMemory = class _GatewayMemory {
|
|
|
1674
2210
|
...runtimeContextPayload2(options)
|
|
1675
2211
|
});
|
|
1676
2212
|
}
|
|
1677
|
-
async delete(target,
|
|
2213
|
+
async delete(target, path2, options = {}) {
|
|
1678
2214
|
const snapshot = typeof target === "string" ? await this.pull(target) : target;
|
|
1679
2215
|
return this.push(snapshot.repo.repoHandle, {
|
|
1680
|
-
files: { [
|
|
2216
|
+
files: { [path2]: null },
|
|
1681
2217
|
parentCommit: options.parentCommit ?? snapshot.commit.commitHash,
|
|
1682
2218
|
message: options.message,
|
|
1683
2219
|
...runtimeContextPayload2(options)
|
|
@@ -1690,8 +2226,8 @@ var GatewayMemory = class _GatewayMemory {
|
|
|
1690
2226
|
payload
|
|
1691
2227
|
);
|
|
1692
2228
|
}
|
|
1693
|
-
async requestJson(method,
|
|
1694
|
-
const response = await fetch(`${this.host}${
|
|
2229
|
+
async requestJson(method, path2, payload) {
|
|
2230
|
+
const response = await fetch(`${this.host}${path2}`, {
|
|
1695
2231
|
method,
|
|
1696
2232
|
headers: {
|
|
1697
2233
|
Authorization: this.authHeader(),
|
|
@@ -1702,7 +2238,7 @@ var GatewayMemory = class _GatewayMemory {
|
|
|
1702
2238
|
const text = await response.text();
|
|
1703
2239
|
const body = text ? safeJson2(text) : {};
|
|
1704
2240
|
if (!response.ok) {
|
|
1705
|
-
const message = typeof body.message === "string" ? body.message : `Gateway API ${response.status} on ${
|
|
2241
|
+
const message = typeof body.message === "string" ? body.message : `Gateway API ${response.status} on ${path2}`;
|
|
1706
2242
|
if (response.status === 409) {
|
|
1707
2243
|
throw new GatewayMemoryConflictError(
|
|
1708
2244
|
message,
|
|
@@ -1711,7 +2247,7 @@ var GatewayMemory = class _GatewayMemory {
|
|
|
1711
2247
|
}
|
|
1712
2248
|
throw new GatewayMemoryError(message);
|
|
1713
2249
|
}
|
|
1714
|
-
this.log("%s %s -> %s", method,
|
|
2250
|
+
this.log("%s %s -> %s", method, path2, response.status);
|
|
1715
2251
|
return body;
|
|
1716
2252
|
}
|
|
1717
2253
|
authHeader() {
|
|
@@ -1873,10 +2409,10 @@ var PersonasClient = class _PersonasClient {
|
|
|
1873
2409
|
done: Boolean(payload.done)
|
|
1874
2410
|
};
|
|
1875
2411
|
}
|
|
1876
|
-
async requestJson(method,
|
|
2412
|
+
async requestJson(method, path2, payload) {
|
|
1877
2413
|
let response;
|
|
1878
2414
|
try {
|
|
1879
|
-
response = await fetch(`${this.host}${
|
|
2415
|
+
response = await fetch(`${this.host}${path2}`, {
|
|
1880
2416
|
method,
|
|
1881
2417
|
headers: {
|
|
1882
2418
|
Authorization: this.authHeader(),
|
|
@@ -1887,7 +2423,7 @@ var PersonasClient = class _PersonasClient {
|
|
|
1887
2423
|
});
|
|
1888
2424
|
} catch (error) {
|
|
1889
2425
|
const reason = error instanceof Error ? error.message : String(error);
|
|
1890
|
-
throw new PersonaError(`${method} ${
|
|
2426
|
+
throw new PersonaError(`${method} ${path2} failed: ${reason}`, {
|
|
1891
2427
|
cause: error
|
|
1892
2428
|
});
|
|
1893
2429
|
}
|
|
@@ -1895,10 +2431,10 @@ var PersonasClient = class _PersonasClient {
|
|
|
1895
2431
|
if (!response.ok) {
|
|
1896
2432
|
const detail = text.slice(0, 500);
|
|
1897
2433
|
throw new PersonaError(
|
|
1898
|
-
`${method} ${
|
|
2434
|
+
`${method} ${path2} failed (${response.status}): ${detail}`
|
|
1899
2435
|
);
|
|
1900
2436
|
}
|
|
1901
|
-
this.log("%s %s -> %s", method,
|
|
2437
|
+
this.log("%s %s -> %s", method, path2, response.status);
|
|
1902
2438
|
return safeJson3(text);
|
|
1903
2439
|
}
|
|
1904
2440
|
authHeader() {
|
|
@@ -2123,10 +2659,10 @@ var SessionRecording = class _SessionRecording {
|
|
|
2123
2659
|
};
|
|
2124
2660
|
}
|
|
2125
2661
|
/** Dump the full session as a JSON fixture (for regression tests). */
|
|
2126
|
-
toFixture(
|
|
2127
|
-
(0, import_node_fs.mkdirSync)((0, import_node_path.dirname)(
|
|
2128
|
-
(0, import_node_fs.writeFileSync)(
|
|
2129
|
-
return
|
|
2662
|
+
toFixture(path2) {
|
|
2663
|
+
(0, import_node_fs.mkdirSync)((0, import_node_path.dirname)(path2), { recursive: true });
|
|
2664
|
+
(0, import_node_fs.writeFileSync)(path2, JSON.stringify(this.toJSON(), null, 2), "utf-8");
|
|
2665
|
+
return path2;
|
|
2130
2666
|
}
|
|
2131
2667
|
static fromApi(raw) {
|
|
2132
2668
|
return new _SessionRecording({
|
|
@@ -2961,7 +3497,7 @@ function randomHex() {
|
|
|
2961
3497
|
return crypto.randomUUID().replace(/-/g, "");
|
|
2962
3498
|
}
|
|
2963
3499
|
function sleep(ms) {
|
|
2964
|
-
return new Promise((
|
|
3500
|
+
return new Promise((resolve2) => setTimeout(resolve2, ms));
|
|
2965
3501
|
}
|
|
2966
3502
|
var replay = {
|
|
2967
3503
|
suite,
|
|
@@ -3048,7 +3584,7 @@ var GatewaySecurity = class _GatewaySecurity {
|
|
|
3048
3584
|
const descriptors = entries.map(
|
|
3049
3585
|
([key, tool]) => this.describeTool(key, tool, options)
|
|
3050
3586
|
);
|
|
3051
|
-
const
|
|
3587
|
+
const resolve2 = await this.resolveToolset({
|
|
3052
3588
|
agent: this.agent,
|
|
3053
3589
|
toolsetId: options.toolsetId,
|
|
3054
3590
|
toolsetName: options.toolsetName,
|
|
@@ -3058,8 +3594,8 @@ var GatewaySecurity = class _GatewaySecurity {
|
|
|
3058
3594
|
});
|
|
3059
3595
|
const securedEntries = entries.flatMap(([key, tool]) => {
|
|
3060
3596
|
const descriptor = descriptors.find((item) => item.name === key);
|
|
3061
|
-
if (!this.shouldExposeTool(
|
|
3062
|
-
this.log("Hiding tool %s in %s mode", descriptor.id,
|
|
3597
|
+
if (!this.shouldExposeTool(resolve2, descriptor.id)) {
|
|
3598
|
+
this.log("Hiding tool %s in %s mode", descriptor.id, resolve2.mode);
|
|
3063
3599
|
return [];
|
|
3064
3600
|
}
|
|
3065
3601
|
return [
|
|
@@ -3069,7 +3605,7 @@ var GatewaySecurity = class _GatewaySecurity {
|
|
|
3069
3605
|
toolId: descriptor.id,
|
|
3070
3606
|
toolsetId: options.toolsetId,
|
|
3071
3607
|
context: this.normalizeContext(options.context),
|
|
3072
|
-
resolve
|
|
3608
|
+
resolve: resolve2
|
|
3073
3609
|
})
|
|
3074
3610
|
]
|
|
3075
3611
|
];
|
|
@@ -3157,8 +3693,8 @@ var GatewaySecurity = class _GatewaySecurity {
|
|
|
3157
3693
|
);
|
|
3158
3694
|
}
|
|
3159
3695
|
}
|
|
3160
|
-
async postJson(
|
|
3161
|
-
const response = await fetch(`${this.host}${
|
|
3696
|
+
async postJson(path2, payload) {
|
|
3697
|
+
const response = await fetch(`${this.host}${path2}`, {
|
|
3162
3698
|
method: "POST",
|
|
3163
3699
|
headers: {
|
|
3164
3700
|
Authorization: this.authHeader(),
|
|
@@ -3169,7 +3705,7 @@ var GatewaySecurity = class _GatewaySecurity {
|
|
|
3169
3705
|
if (!response.ok) {
|
|
3170
3706
|
const body = await response.text();
|
|
3171
3707
|
throw new GatewaySecurityError(
|
|
3172
|
-
`Gateway API ${response.status} on ${
|
|
3708
|
+
`Gateway API ${response.status} on ${path2}: ${body || response.statusText}`
|
|
3173
3709
|
);
|
|
3174
3710
|
}
|
|
3175
3711
|
return await response.json();
|
|
@@ -3184,9 +3720,9 @@ var GatewaySecurity = class _GatewaySecurity {
|
|
|
3184
3720
|
metadata: options.toolMetadata?.[key] ?? {}
|
|
3185
3721
|
};
|
|
3186
3722
|
}
|
|
3187
|
-
shouldExposeTool(
|
|
3188
|
-
if (
|
|
3189
|
-
if (
|
|
3723
|
+
shouldExposeTool(resolve2, toolId) {
|
|
3724
|
+
if (resolve2.mode === "observe") return true;
|
|
3725
|
+
if (resolve2.blockedToolIds.includes(toolId)) return false;
|
|
3190
3726
|
return true;
|
|
3191
3727
|
}
|
|
3192
3728
|
normalizeContext(context4) {
|
|
@@ -3350,10 +3886,10 @@ var UsersClient = class _UsersClient {
|
|
|
3350
3886
|
totalItems: Number(meta.totalItems ?? rows.length)
|
|
3351
3887
|
};
|
|
3352
3888
|
}
|
|
3353
|
-
async requestJson(method,
|
|
3889
|
+
async requestJson(method, path2, payload) {
|
|
3354
3890
|
let response;
|
|
3355
3891
|
try {
|
|
3356
|
-
response = await fetch(`${this.host}${
|
|
3892
|
+
response = await fetch(`${this.host}${path2}`, {
|
|
3357
3893
|
method,
|
|
3358
3894
|
headers: {
|
|
3359
3895
|
Authorization: this.authHeader(),
|
|
@@ -3364,17 +3900,17 @@ var UsersClient = class _UsersClient {
|
|
|
3364
3900
|
});
|
|
3365
3901
|
} catch (error) {
|
|
3366
3902
|
throw new UserProfileError(
|
|
3367
|
-
`${method} ${
|
|
3903
|
+
`${method} ${path2} failed: ${error instanceof Error ? error.message : String(error)}`,
|
|
3368
3904
|
{ cause: error }
|
|
3369
3905
|
);
|
|
3370
3906
|
}
|
|
3371
3907
|
const text = await response.text();
|
|
3372
3908
|
if (!response.ok) {
|
|
3373
3909
|
throw new UserProfileError(
|
|
3374
|
-
`${method} ${
|
|
3910
|
+
`${method} ${path2} failed (${response.status}): ${text.slice(0, 500)}`
|
|
3375
3911
|
);
|
|
3376
3912
|
}
|
|
3377
|
-
this.log("%s %s -> %s", method,
|
|
3913
|
+
this.log("%s %s -> %s", method, path2, response.status);
|
|
3378
3914
|
return safeJson4(text);
|
|
3379
3915
|
}
|
|
3380
3916
|
authHeader() {
|
|
@@ -3578,10 +4114,10 @@ var ScoresClient = class _ScoresClient {
|
|
|
3578
4114
|
metadata: signalMetadata
|
|
3579
4115
|
});
|
|
3580
4116
|
}
|
|
3581
|
-
async request(method,
|
|
4117
|
+
async request(method, path2, payload) {
|
|
3582
4118
|
let response;
|
|
3583
4119
|
try {
|
|
3584
|
-
response = await fetch(`${this.host}${
|
|
4120
|
+
response = await fetch(`${this.host}${path2}`, {
|
|
3585
4121
|
method,
|
|
3586
4122
|
headers: {
|
|
3587
4123
|
Authorization: this.authHeader(),
|
|
@@ -3592,17 +4128,17 @@ var ScoresClient = class _ScoresClient {
|
|
|
3592
4128
|
});
|
|
3593
4129
|
} catch (error) {
|
|
3594
4130
|
throw new ScoreError(
|
|
3595
|
-
`${method} ${
|
|
4131
|
+
`${method} ${path2} failed: ${error instanceof Error ? error.message : String(error)}`,
|
|
3596
4132
|
{ cause: error }
|
|
3597
4133
|
);
|
|
3598
4134
|
}
|
|
3599
4135
|
const text = await response.text();
|
|
3600
4136
|
if (!response.ok) {
|
|
3601
4137
|
throw new ScoreError(
|
|
3602
|
-
`${method} ${
|
|
4138
|
+
`${method} ${path2} failed (${response.status}): ${text.slice(0, 500)}`
|
|
3603
4139
|
);
|
|
3604
4140
|
}
|
|
3605
|
-
this.log("%s %s -> %s", method,
|
|
4141
|
+
this.log("%s %s -> %s", method, path2, response.status);
|
|
3606
4142
|
}
|
|
3607
4143
|
authHeader() {
|
|
3608
4144
|
return `Basic ${Buffer.from(`${this.publicKey}:${this.secretKey}`).toString(
|
|
@@ -3644,7 +4180,7 @@ init_worlds();
|
|
|
3644
4180
|
init_session();
|
|
3645
4181
|
|
|
3646
4182
|
// src/build/index.ts
|
|
3647
|
-
var
|
|
4183
|
+
var import_node_crypto2 = require("crypto");
|
|
3648
4184
|
function canonicalJson(value) {
|
|
3649
4185
|
if (value === null || typeof value !== "object") {
|
|
3650
4186
|
return JSON.stringify(value);
|
|
@@ -3656,7 +4192,7 @@ function canonicalJson(value) {
|
|
|
3656
4192
|
return `{${entries.map(([k, v]) => `${JSON.stringify(k)}:${canonicalJson(v)}`).join(",")}}`;
|
|
3657
4193
|
}
|
|
3658
4194
|
function sha256(text) {
|
|
3659
|
-
return `sha256:${(0,
|
|
4195
|
+
return `sha256:${(0, import_node_crypto2.createHash)("sha256").update(text).digest("hex")}`;
|
|
3660
4196
|
}
|
|
3661
4197
|
var registeredTools = /* @__PURE__ */ new Map();
|
|
3662
4198
|
var registeredPrompts = /* @__PURE__ */ new Map();
|
|
@@ -4525,6 +5061,7 @@ var tracing = {
|
|
|
4525
5061
|
// Annotate the CommonJS export names for ESM import in node:
|
|
4526
5062
|
0 && (module.exports = {
|
|
4527
5063
|
AGENT_ID_KEY,
|
|
5064
|
+
DEFAULT_BRANCH,
|
|
4528
5065
|
DEFAULT_TIMEOUT_SECONDS,
|
|
4529
5066
|
DriftError,
|
|
4530
5067
|
ENV_GATEWAY_HOST,
|
|
@@ -4577,11 +5114,15 @@ var tracing = {
|
|
|
4577
5114
|
assignVariant,
|
|
4578
5115
|
attachSession,
|
|
4579
5116
|
basicAuthHeader,
|
|
5117
|
+
buildSourceTarball,
|
|
4580
5118
|
canonicalJson,
|
|
4581
5119
|
clearExperimentContext,
|
|
5120
|
+
collectArchiveRelPaths,
|
|
4582
5121
|
computeBuildHash,
|
|
5122
|
+
computeContentHash,
|
|
4583
5123
|
computeHash,
|
|
4584
5124
|
context,
|
|
5125
|
+
createRef,
|
|
4585
5126
|
currentTraceId,
|
|
4586
5127
|
defineTool,
|
|
4587
5128
|
deleteEnvSecret,
|
|
@@ -4596,13 +5137,19 @@ var tracing = {
|
|
|
4596
5137
|
getRegisteredTools,
|
|
4597
5138
|
getRun,
|
|
4598
5139
|
identify,
|
|
5140
|
+
isIncludedInContentHash,
|
|
4599
5141
|
listEnvSecretKeys,
|
|
4600
5142
|
listRunConfigs,
|
|
4601
5143
|
loadSession,
|
|
5144
|
+
localTreeState,
|
|
4602
5145
|
memory,
|
|
4603
5146
|
openSession,
|
|
4604
5147
|
openWorld,
|
|
4605
5148
|
personas,
|
|
5149
|
+
propose,
|
|
5150
|
+
pull,
|
|
5151
|
+
push,
|
|
5152
|
+
readLocalMeta,
|
|
4606
5153
|
registerArtifact,
|
|
4607
5154
|
registerPrompt,
|
|
4608
5155
|
registerSkill,
|
|
@@ -4619,10 +5166,13 @@ var tracing = {
|
|
|
4619
5166
|
sessions,
|
|
4620
5167
|
setEnvSecret,
|
|
4621
5168
|
setExperimentContext,
|
|
5169
|
+
snapshotTreeHashes,
|
|
4622
5170
|
success,
|
|
4623
5171
|
suite,
|
|
4624
5172
|
tracing,
|
|
4625
5173
|
users,
|
|
4626
|
-
|
|
5174
|
+
validateWorld,
|
|
5175
|
+
waitForRun,
|
|
5176
|
+
writeLocalMeta
|
|
4627
5177
|
});
|
|
4628
5178
|
//# sourceMappingURL=index.js.map
|