@withgateway/sdk 0.2.5 → 0.2.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +3121 -1283
- package/dist/cli.js.map +1 -1
- package/dist/cli.mjs +3185 -1347
- package/dist/cli.mjs.map +1 -1
- package/dist/files/index.js +9 -0
- package/dist/files/index.js.map +1 -1
- package/dist/files/index.mjs +9 -0
- package/dist/files/index.mjs.map +1 -1
- package/dist/hooks/index.d.mts +1 -1
- package/dist/hooks/index.d.ts +1 -1
- package/dist/hooks/index.js +280 -8
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/index.mjs +272 -8
- package/dist/hooks/index.mjs.map +1 -1
- package/dist/{index-1xnxt0Cc.d.ts → index-BO2SNSgy.d.ts} +12 -1
- package/dist/{index-B0R3IgsV.d.mts → index-BaKu5ZSU.d.mts} +124 -2
- package/dist/{index-B0R3IgsV.d.ts → index-BaKu5ZSU.d.ts} +124 -2
- package/dist/{index-C1wDEwH4.d.mts → index-Cz8Q6Keo.d.mts} +12 -1
- package/dist/index.d.mts +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/index.js +726 -167
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +718 -167
- package/dist/index.mjs.map +1 -1
- package/dist/traces/index.js +9 -0
- package/dist/traces/index.js.map +1 -1
- package/dist/traces/index.mjs +9 -0
- package/dist/traces/index.mjs.map +1 -1
- package/dist/tracing/index.d.mts +1 -1
- package/dist/tracing/index.d.ts +1 -1
- package/dist/tracing/index.js +97 -61
- package/dist/tracing/index.js.map +1 -1
- package/dist/tracing/index.mjs +97 -61
- package/dist/tracing/index.mjs.map +1 -1
- package/dist/worlds/index.d.mts +154 -4
- package/dist/worlds/index.d.ts +154 -4
- package/dist/worlds/index.js +348 -97
- package/dist/worlds/index.js.map +1 -1
- package/dist/worlds/index.mjs +348 -97
- package/dist/worlds/index.mjs.map +1 -1
- package/package.json +1 -1
- package/runtime/gatewaysdk/environment/_bundle.py +1 -1
- package/runtime/gatewaysdk/environment/_materialize.py +53 -9
- package/runtime/gatewaysdk/environment/_toml.py +13 -0
- package/runtime/gatewaysdk/environment/schema/api.py +3 -7
- package/runtime/gatewaysdk/environment/schema/batch.py +15 -11
- package/runtime/gatewaysdk/environment/schema/bundle_runtime.py +24 -0
- package/runtime/gatewaysdk/environment/schema/compiler.py +60 -28
- package/runtime/gatewaysdk/environment/schema/conform.py +1 -1
- package/runtime/gatewaysdk/environment/schema/connector.py +1 -1
- package/runtime/gatewaysdk/environment/schema/connectors/google-drive/readers/merge.ingest.toml +25 -0
- package/runtime/gatewaysdk/environment/schema/connectors/google-drive/readers/merge.toml +17 -0
- package/runtime/gatewaysdk/environment/schema/extract.py +1 -5
- package/runtime/gatewaysdk/environment/schema/host_surfaces.py +1 -5
- package/runtime/gatewaysdk/environment/schema/mapping.py +1 -1
- package/runtime/gatewaysdk/environment/schema/platform.py +16 -4
- package/runtime/gatewaysdk/environment/schema/redaction.py +1 -1
- package/runtime/gatewaysdk/environment/schema/scaffold.py +9 -2
- package/runtime/gatewaysdk/environment/schema/skills/benchmarks-getting-started/SKILL.md +67 -9
- package/runtime/gatewaysdk/environment/schema/skills/hooks-getting-started/SKILL.md +61 -2
- package/runtime/gatewaysdk/environment/schema/skills/world-data-ingestion/SKILL.md +4 -1
- package/runtime/gatewaysdk/environment/schema/skills/worlds-getting-started/SKILL.md +11 -11
- package/runtime/gatewaysdk/environment/schema/skills/worlds-getting-started/references/cli-mcp-map.md +17 -1
- package/runtime/gatewaysdk/environment/schema/snapshot.py +1 -5
- package/runtime/gatewaysdk/environment/schema/tools_world.py +1 -5
- package/runtime/gatewaysdk/environment/schema/ui.py +1 -5
- package/runtime/gatewaysdk/environment/schema/world_tests.py +1 -1
- package/runtime/gatewaysdk/environment/world.py +120 -4
- package/skills/benchmarks-getting-started/SKILL.md +67 -9
- package/skills/connector-schema-authoring/connector-worlds.md +8 -1
- package/skills/connector-schema-authoring/world-schema.md +1 -1
- package/skills/hooks-getting-started/SKILL.md +61 -2
- package/skills/world-data-ingestion/SKILL.md +4 -1
- package/skills/worlds-getting-started/SKILL.md +11 -11
- package/skills/worlds-getting-started/references/cli-mcp-map.md +17 -1
package/dist/index.js
CHANGED
|
@@ -1042,8 +1042,8 @@ async function runSessions(opts) {
|
|
|
1042
1042
|
let tasks = opts.tasks;
|
|
1043
1043
|
let versionId = opts.versionId;
|
|
1044
1044
|
if (!tasks || !versionId) {
|
|
1045
|
-
const { openWorld: openWorld2 } = await Promise.resolve().then(() => (init_worlds(), worlds_exports));
|
|
1046
|
-
const world = await openWorld2(opts.world, options);
|
|
1045
|
+
const { openWorld: openWorld2, openWorldVersion: openWorldVersion2 } = await Promise.resolve().then(() => (init_worlds(), worlds_exports));
|
|
1046
|
+
const world = versionId ? await openWorldVersion2(opts.world.split("@", 1)[0], versionId, options) : await openWorld2(opts.world, options);
|
|
1047
1047
|
tasks = tasks ?? world.tasks.map((t) => t.name);
|
|
1048
1048
|
versionId = versionId ?? world.version.versionId;
|
|
1049
1049
|
}
|
|
@@ -1099,10 +1099,12 @@ async function runSessions(opts) {
|
|
|
1099
1099
|
})
|
|
1100
1100
|
);
|
|
1101
1101
|
const mean = results.reduce((sum, r) => sum + (r.reward ?? 0), 0) / (results.length || 1);
|
|
1102
|
+
const failed = results.filter((r) => r.error).length;
|
|
1102
1103
|
return {
|
|
1103
1104
|
results: results.sort((a, b) => a.task.localeCompare(b.task)),
|
|
1104
1105
|
mean,
|
|
1105
|
-
|
|
1106
|
+
failed,
|
|
1107
|
+
passed: failed === 0 && (opts.failUnder === void 0 || mean >= opts.failUnder)
|
|
1106
1108
|
};
|
|
1107
1109
|
}
|
|
1108
1110
|
var import_node_crypto, isTaskIdRef, isTaskSpec, taskLabel, READY_TIMEOUT_MS, READY_POLL_MS, CALL_TIMEOUT_MS, CALL_POLL_MS, JUDGED_GRADE_TIMEOUT_MS, JUDGED_GRADE_POLL_MS, EXPORT_PAGE, sleep2, modelToolName, WorldSessionTimeout, WorldSessionCallError, WorldSession;
|
|
@@ -2001,7 +2003,7 @@ var require_package = __commonJS({
|
|
|
2001
2003
|
"package.json"(exports2, module2) {
|
|
2002
2004
|
module2.exports = {
|
|
2003
2005
|
name: "@withgateway/sdk",
|
|
2004
|
-
version: "0.2.
|
|
2006
|
+
version: "0.2.6",
|
|
2005
2007
|
description: "Gateway SDK for TypeScript - A/B experiments, tracing, and observability",
|
|
2006
2008
|
main: "./dist/index.js",
|
|
2007
2009
|
module: "./dist/index.mjs",
|
|
@@ -2821,7 +2823,7 @@ async function fileTaskRun(live, runId, model, report, grade, agentError, traced
|
|
|
2821
2823
|
task: live.name ?? live.taskId ?? runId,
|
|
2822
2824
|
rolloutIndex: 0,
|
|
2823
2825
|
prompt: live.instruction,
|
|
2824
|
-
completion: report,
|
|
2826
|
+
...report === null ? {} : { completion: report },
|
|
2825
2827
|
rewards: grade.rewards,
|
|
2826
2828
|
info: {
|
|
2827
2829
|
sessionId: runId,
|
|
@@ -2859,17 +2861,20 @@ async function fileTaskRun(live, runId, model, report, grade, agentError, traced
|
|
|
2859
2861
|
return evaluationId;
|
|
2860
2862
|
}
|
|
2861
2863
|
function reportFromResult(result) {
|
|
2864
|
+
if (result === void 0 || result === null)
|
|
2865
|
+
return { report: null, extra: {} };
|
|
2862
2866
|
if (typeof result === "string") return { report: result, extra: {} };
|
|
2863
|
-
if (
|
|
2864
|
-
|
|
2865
|
-
|
|
2866
|
-
|
|
2867
|
-
|
|
2868
|
-
|
|
2869
|
-
|
|
2870
|
-
|
|
2871
|
-
|
|
2872
|
-
|
|
2867
|
+
if (typeof result !== "object" || Array.isArray(result))
|
|
2868
|
+
throw new Error(
|
|
2869
|
+
`agent returned ${describeValue(result)}; ${RESULT_CONTRACT}`
|
|
2870
|
+
);
|
|
2871
|
+
const { report, ...extra } = result;
|
|
2872
|
+
if (report === void 0 || report === null) return { report: null, extra };
|
|
2873
|
+
if (typeof report !== "string")
|
|
2874
|
+
throw new Error(
|
|
2875
|
+
`agent returned a report of type ${describeValue(report)}; ${RESULT_CONTRACT}`
|
|
2876
|
+
);
|
|
2877
|
+
return { report, extra };
|
|
2873
2878
|
}
|
|
2874
2879
|
async function runTask(ref, agent, opts) {
|
|
2875
2880
|
const runId = `wtr-${(0, import_node_crypto3.randomBytes)(6).toString("hex")}`;
|
|
@@ -2973,7 +2978,7 @@ async function runTask(ref, agent, opts) {
|
|
|
2973
2978
|
}
|
|
2974
2979
|
}
|
|
2975
2980
|
}
|
|
2976
|
-
var import_node_crypto3, fs, path, TaskRun;
|
|
2981
|
+
var import_node_crypto3, fs, path, TaskRun, describeValue, RESULT_CONTRACT;
|
|
2977
2982
|
var init_taskRun = __esm({
|
|
2978
2983
|
"src/worlds/taskRun.ts"() {
|
|
2979
2984
|
"use strict";
|
|
@@ -3047,6 +3052,8 @@ var init_taskRun = __esm({
|
|
|
3047
3052
|
Object.assign(this.notes, notes);
|
|
3048
3053
|
}
|
|
3049
3054
|
};
|
|
3055
|
+
describeValue = (value) => Array.isArray(value) ? "array" : value === null ? "null" : typeof value;
|
|
3056
|
+
RESULT_CONTRACT = "return a string report, an object {report?: string, ...} or nothing";
|
|
3050
3057
|
}
|
|
3051
3058
|
});
|
|
3052
3059
|
|
|
@@ -3200,16 +3207,21 @@ var init_worldDir = __esm({
|
|
|
3200
3207
|
var hub_exports = {};
|
|
3201
3208
|
__export(hub_exports, {
|
|
3202
3209
|
DEFAULT_BRANCH: () => DEFAULT_BRANCH,
|
|
3210
|
+
PushSlugConflict: () => PushSlugConflict,
|
|
3211
|
+
archiveMode: () => archiveMode,
|
|
3212
|
+
buildFileManifest: () => buildFileManifest,
|
|
3203
3213
|
buildSourceTarball: () => buildSourceTarball,
|
|
3204
3214
|
collectArchiveRelPaths: () => collectArchiveRelPaths,
|
|
3205
3215
|
computeContentHash: () => computeContentHash,
|
|
3206
3216
|
createRef: () => createRef,
|
|
3217
|
+
extractBundle: () => extractBundle,
|
|
3207
3218
|
localTreeState: () => localTreeState,
|
|
3208
3219
|
propose: () => propose,
|
|
3209
3220
|
pull: () => pull,
|
|
3210
3221
|
push: () => push,
|
|
3211
3222
|
pushSlug: () => pushSlug,
|
|
3212
3223
|
readLocalMeta: () => readLocalMeta,
|
|
3224
|
+
resolvePushSlug: () => resolvePushSlug,
|
|
3213
3225
|
snapshotTreeHashes: () => snapshotTreeHashes,
|
|
3214
3226
|
writeLocalMeta: () => writeLocalMeta
|
|
3215
3227
|
});
|
|
@@ -3227,12 +3239,18 @@ function computeContentHash(dir) {
|
|
|
3227
3239
|
return WorldDir.open(dir).contentHash;
|
|
3228
3240
|
}
|
|
3229
3241
|
function octal(value, length) {
|
|
3230
|
-
return Buffer.from(
|
|
3242
|
+
return Buffer.from(
|
|
3243
|
+
value.toString(8).padStart(length - 1, "0") + "\0",
|
|
3244
|
+
"ascii"
|
|
3245
|
+
);
|
|
3246
|
+
}
|
|
3247
|
+
function archiveMode(mode) {
|
|
3248
|
+
return (mode & 73) !== 0 ? EXEC_MODE : FILE_MODE;
|
|
3231
3249
|
}
|
|
3232
|
-
function tarHeader(name, size) {
|
|
3250
|
+
function tarHeader(name, size, mode = FILE_MODE) {
|
|
3233
3251
|
const header = Buffer.alloc(512);
|
|
3234
3252
|
header.write(name, 0, 100, "utf-8");
|
|
3235
|
-
octal(
|
|
3253
|
+
octal(mode, 8).copy(header, 100);
|
|
3236
3254
|
octal(0, 8).copy(header, 108);
|
|
3237
3255
|
octal(0, 8).copy(header, 116);
|
|
3238
3256
|
octal(size, 12).copy(header, 124);
|
|
@@ -3246,7 +3264,7 @@ function tarHeader(name, size) {
|
|
|
3246
3264
|
header.write(sum.toString(8).padStart(6, "0") + "\0 ", 148, "ascii");
|
|
3247
3265
|
return header;
|
|
3248
3266
|
}
|
|
3249
|
-
function tarMember(name, payload) {
|
|
3267
|
+
function tarMember(name, payload, mode) {
|
|
3250
3268
|
const parts2 = [];
|
|
3251
3269
|
const nameBytes = Buffer.byteLength(name, "utf-8");
|
|
3252
3270
|
if (nameBytes > 100) {
|
|
@@ -3260,9 +3278,9 @@ function tarMember(name, payload) {
|
|
|
3260
3278
|
parts2.push(lHeader, body);
|
|
3261
3279
|
const pad2 = body.length % 512 === 0 ? 0 : 512 - body.length % 512;
|
|
3262
3280
|
if (pad2) parts2.push(Buffer.alloc(pad2));
|
|
3263
|
-
parts2.push(tarHeader(name.slice(0, 100), payload.length));
|
|
3281
|
+
parts2.push(tarHeader(name.slice(0, 100), payload.length, mode));
|
|
3264
3282
|
} else {
|
|
3265
|
-
parts2.push(tarHeader(name, payload.length));
|
|
3283
|
+
parts2.push(tarHeader(name, payload.length, mode));
|
|
3266
3284
|
}
|
|
3267
3285
|
parts2.push(payload);
|
|
3268
3286
|
const pad = payload.length % 512 === 0 ? 0 : 512 - payload.length % 512;
|
|
@@ -3272,7 +3290,14 @@ function tarMember(name, payload) {
|
|
|
3272
3290
|
function buildSourceTarball(dir) {
|
|
3273
3291
|
const parts2 = [];
|
|
3274
3292
|
for (const relPath of collectArchiveRelPaths(dir)) {
|
|
3275
|
-
|
|
3293
|
+
const abs = path3.join(dir, relPath);
|
|
3294
|
+
parts2.push(
|
|
3295
|
+
...tarMember(
|
|
3296
|
+
relPath,
|
|
3297
|
+
fs3.readFileSync(abs),
|
|
3298
|
+
archiveMode(fs3.statSync(abs).mode)
|
|
3299
|
+
)
|
|
3300
|
+
);
|
|
3276
3301
|
}
|
|
3277
3302
|
parts2.push(Buffer.alloc(1024));
|
|
3278
3303
|
return (0, import_node_zlib.gzipSync)(Buffer.concat(parts2), { level: 9 });
|
|
@@ -3287,10 +3312,22 @@ function readLocalMeta(dir) {
|
|
|
3287
3312
|
}
|
|
3288
3313
|
}
|
|
3289
3314
|
function pushSlug(dir, explicit) {
|
|
3290
|
-
|
|
3315
|
+
return resolvePushSlug(dir, { explicit }).slug;
|
|
3316
|
+
}
|
|
3317
|
+
function resolvePushSlug(dir, opts = {}) {
|
|
3291
3318
|
const meta = readLocalMeta(dir);
|
|
3292
|
-
|
|
3293
|
-
|
|
3319
|
+
const tracked = typeof meta?.slug === "string" && meta.slug ? meta.slug : null;
|
|
3320
|
+
const declared = Object.entries({ ...opts.declared ?? {}, "pyproject.toml": readPyproject(dir).name }).filter((entry) => typeof entry[1] === "string" && entry[1] !== "").map(([source, slug]) => ({ source, slug }));
|
|
3321
|
+
const base = { tracked, declared, conflict: null };
|
|
3322
|
+
if (opts.explicit) return { ...base, slug: opts.explicit, source: "--slug" };
|
|
3323
|
+
if (tracked) {
|
|
3324
|
+
const minted = (d) => tracked.startsWith(d.slug) && MINTED_SUFFIX.test(tracked.slice(d.slug.length));
|
|
3325
|
+
const conflict = declared.find((d) => d.slug !== tracked && !minted(d)) ?? null;
|
|
3326
|
+
return { ...base, slug: tracked, source: ".gateway metadata", conflict };
|
|
3327
|
+
}
|
|
3328
|
+
const first = declared[0];
|
|
3329
|
+
if (first) return { ...base, slug: first.slug, source: first.source };
|
|
3330
|
+
return { ...base, slug: path3.basename(path3.resolve(dir)), source: "directory name" };
|
|
3294
3331
|
}
|
|
3295
3332
|
function writeLocalMeta(dir, meta) {
|
|
3296
3333
|
fs3.mkdirSync(path3.join(dir, ".gateway"), { recursive: true });
|
|
@@ -3329,7 +3366,9 @@ function readPyproject(dir) {
|
|
|
3329
3366
|
function readWorldContractVersion(dir) {
|
|
3330
3367
|
const world = WorldDir.open(dir);
|
|
3331
3368
|
try {
|
|
3332
|
-
const parsed = JSON.parse(
|
|
3369
|
+
const parsed = JSON.parse(
|
|
3370
|
+
world.text(world.worldPath("schema/world.json")) ?? ""
|
|
3371
|
+
);
|
|
3333
3372
|
const pkg = parsed["x-gateway"]?.package;
|
|
3334
3373
|
if (pkg?.version) return { name: pkg.id, version: pkg.version };
|
|
3335
3374
|
} catch {
|
|
@@ -3337,28 +3376,15 @@ function readWorldContractVersion(dir) {
|
|
|
3337
3376
|
return {};
|
|
3338
3377
|
}
|
|
3339
3378
|
function buildFileManifest(dir) {
|
|
3340
|
-
|
|
3341
|
-
|
|
3342
|
-
|
|
3343
|
-
|
|
3344
|
-
|
|
3345
|
-
|
|
3346
|
-
|
|
3347
|
-
|
|
3348
|
-
|
|
3349
|
-
} else if (entry.isFile()) {
|
|
3350
|
-
const payload = fs3.readFileSync(path3.join(dir, childRel));
|
|
3351
|
-
entries.push({
|
|
3352
|
-
path: childRel,
|
|
3353
|
-
isDirectory: false,
|
|
3354
|
-
size: payload.length,
|
|
3355
|
-
sha256: (0, import_node_crypto5.createHash)("sha256").update(payload).digest("hex")
|
|
3356
|
-
});
|
|
3357
|
-
}
|
|
3358
|
-
}
|
|
3359
|
-
};
|
|
3360
|
-
walk("");
|
|
3361
|
-
return entries;
|
|
3379
|
+
return collectArchiveRelPaths(dir).map((relPath) => {
|
|
3380
|
+
const payload = fs3.readFileSync(path3.join(dir, relPath));
|
|
3381
|
+
return {
|
|
3382
|
+
path: relPath,
|
|
3383
|
+
isDirectory: false,
|
|
3384
|
+
size: payload.length,
|
|
3385
|
+
sha256: (0, import_node_crypto5.createHash)("sha256").update(payload).digest("hex")
|
|
3386
|
+
};
|
|
3387
|
+
});
|
|
3362
3388
|
}
|
|
3363
3389
|
async function putObject(url, data, shaB64) {
|
|
3364
3390
|
const resp = await fetch(url, {
|
|
@@ -3370,22 +3396,30 @@ async function putObject(url, data, shaB64) {
|
|
|
3370
3396
|
body: new Uint8Array(data)
|
|
3371
3397
|
});
|
|
3372
3398
|
if (!resp.ok) {
|
|
3373
|
-
throw new Error(
|
|
3399
|
+
throw new Error(
|
|
3400
|
+
`object PUT -> ${resp.status}: ${(await resp.text()).slice(0, 300)}`
|
|
3401
|
+
);
|
|
3374
3402
|
}
|
|
3375
3403
|
}
|
|
3376
3404
|
async function push(dir, opts = {}) {
|
|
3377
3405
|
const options = opts.options ?? {};
|
|
3378
|
-
if (!fs3.statSync(dir).isDirectory())
|
|
3406
|
+
if (!fs3.statSync(dir).isDirectory())
|
|
3407
|
+
throw new Error(`Not a directory: ${dir}`);
|
|
3379
3408
|
const localMeta = readLocalMeta(dir) ?? {};
|
|
3380
3409
|
const branch = opts.branch ?? localMeta.branch ?? DEFAULT_BRANCH;
|
|
3381
3410
|
const baseVersionId = opts.baseVersionId ?? localMeta.versionId ?? null;
|
|
3411
|
+
const fileManifest = buildFileManifest(dir);
|
|
3412
|
+
if (fileManifest.length === 0)
|
|
3413
|
+
throw new Error(
|
|
3414
|
+
`Nothing to push: ${dir} has no files the archive rules keep (a world root marker, README.md, pyproject.toml, *.py, or any file below a subdirectory).`
|
|
3415
|
+
);
|
|
3382
3416
|
const contentHash = computeContentHash(dir);
|
|
3383
3417
|
const pyproject = readPyproject(dir);
|
|
3384
3418
|
const contractVersion = pyproject.version ? void 0 : readWorldContractVersion(dir).version;
|
|
3385
3419
|
if (contractVersion) pyproject.version = contractVersion;
|
|
3386
3420
|
const slug = opts.slug ?? localMeta.slug ?? pyproject.name ?? path3.basename(path3.resolve(dir));
|
|
3387
3421
|
const metadata = {
|
|
3388
|
-
name: opts.name
|
|
3422
|
+
...opts.name !== void 0 ? { name: opts.name } : {},
|
|
3389
3423
|
...opts.description !== void 0 ? { description: opts.description } : {},
|
|
3390
3424
|
...opts.tags !== void 0 ? { tags: opts.tags } : {},
|
|
3391
3425
|
...opts.visibility ? { visibility: opts.visibility } : {}
|
|
@@ -3405,7 +3439,7 @@ async function push(dir, opts = {}) {
|
|
|
3405
3439
|
bundleSizeBytes: tarball.length,
|
|
3406
3440
|
...pyproject.version ? { semanticVersion: pyproject.version } : {},
|
|
3407
3441
|
pyprojectMeta: pyproject,
|
|
3408
|
-
fileManifest
|
|
3442
|
+
fileManifest,
|
|
3409
3443
|
branch,
|
|
3410
3444
|
baseVersionId,
|
|
3411
3445
|
...opts.force ? { force: true } : {},
|
|
@@ -3413,12 +3447,18 @@ async function push(dir, opts = {}) {
|
|
|
3413
3447
|
...opts.author ? { author: opts.author } : {},
|
|
3414
3448
|
...opts.imageRef ? { imageRef: opts.imageRef } : {}
|
|
3415
3449
|
});
|
|
3416
|
-
if (version.uploadUrl)
|
|
3450
|
+
if (version.uploadUrl)
|
|
3451
|
+
await putObject(version.uploadUrl, tarball, bundleSha256);
|
|
3417
3452
|
const final = await apiRequest(
|
|
3418
3453
|
options,
|
|
3419
3454
|
"POST",
|
|
3420
3455
|
`/api/public/benchmark-containers/versions/${version.versionId}/finalize`,
|
|
3421
|
-
{
|
|
3456
|
+
{
|
|
3457
|
+
branch,
|
|
3458
|
+
baseVersionId,
|
|
3459
|
+
...opts.force ? { force: true } : {},
|
|
3460
|
+
...metadata
|
|
3461
|
+
}
|
|
3422
3462
|
);
|
|
3423
3463
|
writeLocalMeta(dir, {
|
|
3424
3464
|
...localMeta,
|
|
@@ -3451,7 +3491,14 @@ function extractBundle(bundle, dir) {
|
|
|
3451
3491
|
offset += 512;
|
|
3452
3492
|
if (header.every((b) => b === 0)) break;
|
|
3453
3493
|
const rawName = header.subarray(0, 100).toString("utf-8").replace(/\0.*$/, "");
|
|
3454
|
-
const size = parseInt(
|
|
3494
|
+
const size = parseInt(
|
|
3495
|
+
header.subarray(124, 136).toString("ascii").replace(/\0.*$/, "").trim(),
|
|
3496
|
+
8
|
|
3497
|
+
) || 0;
|
|
3498
|
+
const mode = parseInt(
|
|
3499
|
+
header.subarray(100, 108).toString("ascii").replace(/\0.*$/, "").trim(),
|
|
3500
|
+
8
|
|
3501
|
+
) || FILE_MODE;
|
|
3455
3502
|
const typeflag = header.subarray(156, 157).toString("ascii");
|
|
3456
3503
|
const body = tar.subarray(offset, offset + size);
|
|
3457
3504
|
offset += size + (size % 512 === 0 ? 0 : 512 - size % 512);
|
|
@@ -3465,7 +3512,8 @@ function extractBundle(bundle, dir) {
|
|
|
3465
3512
|
if (name.startsWith("/") || name.split("/").includes("..")) continue;
|
|
3466
3513
|
const target = path3.join(dir, name);
|
|
3467
3514
|
fs3.mkdirSync(path3.dirname(target), { recursive: true });
|
|
3468
|
-
fs3.writeFileSync(target, body);
|
|
3515
|
+
fs3.writeFileSync(target, body, { mode: archiveMode(mode) });
|
|
3516
|
+
fs3.chmodSync(target, archiveMode(mode));
|
|
3469
3517
|
written++;
|
|
3470
3518
|
}
|
|
3471
3519
|
return written;
|
|
@@ -3512,13 +3560,17 @@ async function pull(slugRef, target, options = {}) {
|
|
|
3512
3560
|
async function propose(dir, opts) {
|
|
3513
3561
|
const meta = readLocalMeta(dir);
|
|
3514
3562
|
if (!meta?.slug || !meta.baseFiles) {
|
|
3515
|
-
throw new Error(
|
|
3563
|
+
throw new Error(
|
|
3564
|
+
"This dir has no pull/push base \u2014 run pull first, then edit, then propose."
|
|
3565
|
+
);
|
|
3516
3566
|
}
|
|
3517
3567
|
const state2 = localTreeState(dir);
|
|
3518
|
-
if (state2.clean)
|
|
3568
|
+
if (state2.clean)
|
|
3569
|
+
throw new Error("Nothing to propose \u2014 the tree matches its base.");
|
|
3519
3570
|
const changes = state2.dirty.map((relPath) => {
|
|
3520
3571
|
const abs = path3.join(dir, relPath);
|
|
3521
|
-
if (!fs3.existsSync(abs))
|
|
3572
|
+
if (!fs3.existsSync(abs))
|
|
3573
|
+
return { path: relPath, action: "delete" };
|
|
3522
3574
|
return {
|
|
3523
3575
|
path: relPath,
|
|
3524
3576
|
action: "write",
|
|
@@ -3548,7 +3600,7 @@ async function createRef(slug, name, kind, versionId, options = {}) {
|
|
|
3548
3600
|
...versionId ? { versionId } : {}
|
|
3549
3601
|
});
|
|
3550
3602
|
}
|
|
3551
|
-
var import_node_crypto5, import_node_zlib, fs3, path3, DEFAULT_BRANCH, META_RELPATH,
|
|
3603
|
+
var import_node_crypto5, import_node_zlib, fs3, path3, DEFAULT_BRANCH, META_RELPATH, FILE_MODE, EXEC_MODE, MINTED_SUFFIX, PushSlugConflict, sha256b64;
|
|
3552
3604
|
var init_hub = __esm({
|
|
3553
3605
|
"src/worlds/hub.ts"() {
|
|
3554
3606
|
"use strict";
|
|
@@ -3560,16 +3612,20 @@ var init_hub = __esm({
|
|
|
3560
3612
|
init_worldDir();
|
|
3561
3613
|
DEFAULT_BRANCH = "main";
|
|
3562
3614
|
META_RELPATH = path3.join(".gateway", ".env-metadata.json");
|
|
3563
|
-
|
|
3564
|
-
|
|
3565
|
-
|
|
3566
|
-
|
|
3567
|
-
|
|
3568
|
-
|
|
3569
|
-
|
|
3570
|
-
|
|
3571
|
-
|
|
3572
|
-
|
|
3615
|
+
FILE_MODE = 420;
|
|
3616
|
+
EXEC_MODE = 493;
|
|
3617
|
+
MINTED_SUFFIX = /^-\d+$/;
|
|
3618
|
+
PushSlugConflict = class extends Error {
|
|
3619
|
+
constructor(dir, tracked, declared) {
|
|
3620
|
+
super(
|
|
3621
|
+
`${dir} tracks slug \`${tracked}\` (${META_RELPATH}, from an earlier push) but its ${declared.source} says \`${declared.slug}\`. Nothing was pushed. Pass --slug ${declared.slug} to push there (and retrack the dir), --slug ${tracked} to keep pushing to \`${tracked}\`, or delete ${META_RELPATH} to forget the earlier push.`
|
|
3622
|
+
);
|
|
3623
|
+
this.dir = dir;
|
|
3624
|
+
this.tracked = tracked;
|
|
3625
|
+
this.declared = declared;
|
|
3626
|
+
this.name = "PushSlugConflict";
|
|
3627
|
+
}
|
|
3628
|
+
};
|
|
3573
3629
|
sha256b64 = (data) => (0, import_node_crypto5.createHash)("sha256").update(data).digest("base64");
|
|
3574
3630
|
}
|
|
3575
3631
|
});
|
|
@@ -4143,8 +4199,8 @@ function hashForm(slug, plaintext) {
|
|
|
4143
4199
|
}
|
|
4144
4200
|
function preserveForm(slug, plaintext) {
|
|
4145
4201
|
const kind = typeof plaintext === "string" ? "str" : isInt(plaintext) ? "int" : "float";
|
|
4146
|
-
const
|
|
4147
|
-
return kind === "str" ?
|
|
4202
|
+
const shaped2 = shapeText(slug, pyText(plaintext), kind);
|
|
4203
|
+
return kind === "str" ? shaped2 : Number(shaped2);
|
|
4148
4204
|
}
|
|
4149
4205
|
function shapeText(slug, text2, kind) {
|
|
4150
4206
|
const seed = Buffer.from(`${slug}:${text2}`, "utf8");
|
|
@@ -4278,11 +4334,20 @@ var init_router = __esm({
|
|
|
4278
4334
|
});
|
|
4279
4335
|
|
|
4280
4336
|
// src/cli/config.ts
|
|
4337
|
+
function transportDetail(error, timeoutMs) {
|
|
4338
|
+
if (error instanceof Error && error.name === "AbortError") return `timed out after ${Math.round(timeoutMs / 1e3)}s`;
|
|
4339
|
+
const cause = error instanceof Error && error.cause instanceof Error ? error.cause : void 0;
|
|
4340
|
+
const code = cause && "code" in cause && typeof cause.code === "string" ? `${cause.code}: ` : "";
|
|
4341
|
+
const message = cause?.message ?? (error instanceof Error ? error.message : String(error));
|
|
4342
|
+
return `${code}${message}`;
|
|
4343
|
+
}
|
|
4281
4344
|
async function api(creds, method, route, body, init3 = {}) {
|
|
4282
4345
|
const controller = new AbortController();
|
|
4283
|
-
const
|
|
4346
|
+
const timeoutMs = init3.timeoutMs ?? 12e4;
|
|
4347
|
+
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
4348
|
+
let res;
|
|
4284
4349
|
try {
|
|
4285
|
-
|
|
4350
|
+
res = await fetch(`${creds.host}${route}`, {
|
|
4286
4351
|
method,
|
|
4287
4352
|
headers: {
|
|
4288
4353
|
"content-type": "application/json",
|
|
@@ -4292,6 +4357,11 @@ async function api(creds, method, route, body, init3 = {}) {
|
|
|
4292
4357
|
...body === void 0 ? {} : { body: JSON.stringify(body) },
|
|
4293
4358
|
signal: controller.signal
|
|
4294
4359
|
});
|
|
4360
|
+
} catch (error) {
|
|
4361
|
+
clearTimeout(timer);
|
|
4362
|
+
throw new UnreachableError(creds.host, method, route, transportDetail(error, timeoutMs));
|
|
4363
|
+
}
|
|
4364
|
+
try {
|
|
4295
4365
|
const text2 = await res.text();
|
|
4296
4366
|
if (!res.ok) throw new ApiError(res.status, method, route, text2);
|
|
4297
4367
|
return text2 ? JSON.parse(text2) : {};
|
|
@@ -4299,7 +4369,7 @@ async function api(creds, method, route, body, init3 = {}) {
|
|
|
4299
4369
|
clearTimeout(timer);
|
|
4300
4370
|
}
|
|
4301
4371
|
}
|
|
4302
|
-
var fs4, os, path4, ApiError;
|
|
4372
|
+
var fs4, os, path4, ApiError, UnreachableError;
|
|
4303
4373
|
var init_config = __esm({
|
|
4304
4374
|
"src/cli/config.ts"() {
|
|
4305
4375
|
"use strict";
|
|
@@ -4316,6 +4386,15 @@ var init_config = __esm({
|
|
|
4316
4386
|
this.text = text2;
|
|
4317
4387
|
}
|
|
4318
4388
|
};
|
|
4389
|
+
UnreachableError = class extends CliError {
|
|
4390
|
+
constructor(host, method, route, detail) {
|
|
4391
|
+
super(`${method} ${route}: no answer from ${host} (${detail}). Check the host and the network, then retry.`, 1);
|
|
4392
|
+
this.host = host;
|
|
4393
|
+
this.method = method;
|
|
4394
|
+
this.route = route;
|
|
4395
|
+
this.detail = detail;
|
|
4396
|
+
}
|
|
4397
|
+
};
|
|
4319
4398
|
}
|
|
4320
4399
|
});
|
|
4321
4400
|
|
|
@@ -4529,7 +4608,7 @@ function readWorldFiles(dir, opts = {}) {
|
|
|
4529
4608
|
for (const entry of entries) {
|
|
4530
4609
|
const childRel = rel ? `${rel}/${entry.name}` : entry.name;
|
|
4531
4610
|
if (entry.isDirectory()) {
|
|
4532
|
-
if (!
|
|
4611
|
+
if (!SKIP_DIRS.has(entry.name)) walk(childRel);
|
|
4533
4612
|
} else if (entry.isFile()) {
|
|
4534
4613
|
if (!opts.buildOutputs && isBuildOutput(childRel)) continue;
|
|
4535
4614
|
out.push({
|
|
@@ -4572,7 +4651,7 @@ function pruneEmptyDirs(root) {
|
|
|
4572
4651
|
for (const entry of fs6.readdirSync(abs, { withFileTypes: true })) {
|
|
4573
4652
|
const child = path6.join(abs, entry.name);
|
|
4574
4653
|
if (entry.isDirectory()) {
|
|
4575
|
-
if (
|
|
4654
|
+
if (SKIP_DIRS.has(entry.name)) {
|
|
4576
4655
|
empty = false;
|
|
4577
4656
|
continue;
|
|
4578
4657
|
}
|
|
@@ -4640,7 +4719,7 @@ async function runtime(creds, request, opts = {}) {
|
|
|
4640
4719
|
clearTimeout(timer);
|
|
4641
4720
|
}
|
|
4642
4721
|
}
|
|
4643
|
-
var fs6, path6,
|
|
4722
|
+
var fs6, path6, SKIP_DIRS, BUILD_OUTPUT, BridgeRejected;
|
|
4644
4723
|
var init_client = __esm({
|
|
4645
4724
|
"src/cli/runtime/client.ts"() {
|
|
4646
4725
|
"use strict";
|
|
@@ -4648,7 +4727,7 @@ var init_client = __esm({
|
|
|
4648
4727
|
path6 = __toESM(require("path"));
|
|
4649
4728
|
init_router();
|
|
4650
4729
|
init_local();
|
|
4651
|
-
|
|
4730
|
+
SKIP_DIRS = /* @__PURE__ */ new Set(["__pycache__", ".git", "node_modules", ".gateway"]);
|
|
4652
4731
|
BUILD_OUTPUT = /(^|\/)state\.(sqlite|json)$/;
|
|
4653
4732
|
BridgeRejected = class extends CliError {
|
|
4654
4733
|
constructor(detail) {
|
|
@@ -5069,7 +5148,12 @@ var init_batches = __esm({
|
|
|
5069
5148
|
fs9 = __toESM(require("fs"));
|
|
5070
5149
|
init_config();
|
|
5071
5150
|
init_router();
|
|
5072
|
-
TERMINAL_STATES = /* @__PURE__ */ new Set([
|
|
5151
|
+
TERMINAL_STATES = /* @__PURE__ */ new Set([
|
|
5152
|
+
"applied",
|
|
5153
|
+
"refused",
|
|
5154
|
+
"published",
|
|
5155
|
+
"failed"
|
|
5156
|
+
]);
|
|
5073
5157
|
sleepMs = (ms) => new Promise((resolve10) => setTimeout(resolve10, ms));
|
|
5074
5158
|
WorldDataApi = class {
|
|
5075
5159
|
constructor(creds, slug, sleep3 = sleepMs) {
|
|
@@ -5083,22 +5167,61 @@ var init_batches = __esm({
|
|
|
5083
5167
|
return api(this.creds, "POST", `${this.base}/batches`, body);
|
|
5084
5168
|
}
|
|
5085
5169
|
register(batchId, chunk) {
|
|
5086
|
-
return api(
|
|
5170
|
+
return api(
|
|
5171
|
+
this.creds,
|
|
5172
|
+
"POST",
|
|
5173
|
+
`${this.base}/batches/${batchId}/chunks`,
|
|
5174
|
+
{
|
|
5175
|
+
ordinal: chunk.ordinal,
|
|
5176
|
+
digest: chunk.digest,
|
|
5177
|
+
bytes: chunk.bytes,
|
|
5178
|
+
rows: chunk.rows,
|
|
5179
|
+
...chunk.entity ? { entity: chunk.entity } : {}
|
|
5180
|
+
}
|
|
5181
|
+
);
|
|
5182
|
+
}
|
|
5183
|
+
/**
|
|
5184
|
+
* Stage a project-drive rows file as one chunk, on the platform: the server
|
|
5185
|
+
* streams it out of drive storage into chunk storage and answers with the
|
|
5186
|
+
* digest and gzipped size it derived. No bytes pass through this process.
|
|
5187
|
+
*/
|
|
5188
|
+
async stageDrive(batchId, chunk) {
|
|
5189
|
+
const staged = await api(this.creds, "POST", `${this.base}/batches/${batchId}/chunks`, {
|
|
5087
5190
|
ordinal: chunk.ordinal,
|
|
5088
|
-
|
|
5089
|
-
bytes: chunk.bytes,
|
|
5090
|
-
rows: chunk.rows,
|
|
5191
|
+
drive: chunk.path,
|
|
5091
5192
|
...chunk.entity ? { entity: chunk.entity } : {}
|
|
5092
5193
|
});
|
|
5194
|
+
if (!staged.uploaded || !staged.digest || staged.bytes === void 0 || staged.rows === void 0)
|
|
5195
|
+
throw new CliError(
|
|
5196
|
+
`the server staged drive:${chunk.path} as chunk ${chunk.ordinal} without its digest, size and rows`,
|
|
5197
|
+
1
|
|
5198
|
+
);
|
|
5199
|
+
return {
|
|
5200
|
+
ordinal: chunk.ordinal,
|
|
5201
|
+
digest: staged.digest,
|
|
5202
|
+
bytes: staged.bytes,
|
|
5203
|
+
rows: staged.rows,
|
|
5204
|
+
entity: chunk.entity,
|
|
5205
|
+
chunkId: staged.chunkId,
|
|
5206
|
+
uploaded: true
|
|
5207
|
+
};
|
|
5093
5208
|
}
|
|
5094
5209
|
markUploaded(batchId, chunkId) {
|
|
5095
|
-
return api(
|
|
5210
|
+
return api(
|
|
5211
|
+
this.creds,
|
|
5212
|
+
"POST",
|
|
5213
|
+
`${this.base}/batches/${batchId}/chunks/${chunkId}/uploaded`
|
|
5214
|
+
);
|
|
5096
5215
|
}
|
|
5097
5216
|
complete(batchId) {
|
|
5098
5217
|
return api(this.creds, "POST", `${this.base}/batches/${batchId}/complete`);
|
|
5099
5218
|
}
|
|
5100
5219
|
get(batchId) {
|
|
5101
|
-
return api(
|
|
5220
|
+
return api(
|
|
5221
|
+
this.creds,
|
|
5222
|
+
"GET",
|
|
5223
|
+
`${this.base}/batches/${batchId}`
|
|
5224
|
+
);
|
|
5102
5225
|
}
|
|
5103
5226
|
list(limit, cursor) {
|
|
5104
5227
|
const params = new URLSearchParams();
|
|
@@ -5108,7 +5231,12 @@ var init_batches = __esm({
|
|
|
5108
5231
|
return api(this.creds, "GET", `${this.base}/batches${q ? `?${q}` : ""}`);
|
|
5109
5232
|
}
|
|
5110
5233
|
publish(message) {
|
|
5111
|
-
return api(
|
|
5234
|
+
return api(
|
|
5235
|
+
this.creds,
|
|
5236
|
+
"POST",
|
|
5237
|
+
`${this.base}/publish`,
|
|
5238
|
+
message ? { message } : {}
|
|
5239
|
+
);
|
|
5112
5240
|
}
|
|
5113
5241
|
/**
|
|
5114
5242
|
* PUT the gzipped chunk to its presigned URL with exactly the headers the
|
|
@@ -5120,11 +5248,23 @@ var init_batches = __esm({
|
|
|
5120
5248
|
const delays = [500, 1500, 4e3];
|
|
5121
5249
|
for (let attempt = 0; ; attempt++) {
|
|
5122
5250
|
try {
|
|
5123
|
-
const res = await fetch(uploadUrl, {
|
|
5251
|
+
const res = await fetch(uploadUrl, {
|
|
5252
|
+
method: "PUT",
|
|
5253
|
+
body: new Uint8Array(gz),
|
|
5254
|
+
headers
|
|
5255
|
+
});
|
|
5124
5256
|
if (res.ok) return;
|
|
5125
|
-
if (res.status < 500 || attempt >= delays.length)
|
|
5257
|
+
if (res.status < 500 || attempt >= delays.length)
|
|
5258
|
+
throw new CliError(
|
|
5259
|
+
`chunk upload -> ${res.status}: ${(await res.text()).slice(0, 300)}`,
|
|
5260
|
+
1
|
|
5261
|
+
);
|
|
5126
5262
|
} catch (error) {
|
|
5127
|
-
if (error instanceof CliError || attempt >= delays.length)
|
|
5263
|
+
if (error instanceof CliError || attempt >= delays.length)
|
|
5264
|
+
throw error instanceof CliError ? error : new CliError(
|
|
5265
|
+
`chunk upload failed: ${error.message}`,
|
|
5266
|
+
1
|
|
5267
|
+
);
|
|
5128
5268
|
}
|
|
5129
5269
|
await this.sleep(delays[attempt]);
|
|
5130
5270
|
}
|
|
@@ -5133,11 +5273,23 @@ var init_batches = __esm({
|
|
|
5133
5273
|
async upload(batchId, chunk) {
|
|
5134
5274
|
const registered = await this.register(batchId, chunk);
|
|
5135
5275
|
if (!registered.uploaded) {
|
|
5136
|
-
if (!registered.uploadUrl)
|
|
5276
|
+
if (!registered.uploadUrl)
|
|
5277
|
+
throw new CliError(
|
|
5278
|
+
`the server registered chunk ${chunk.ordinal} without an upload URL`,
|
|
5279
|
+
1
|
|
5280
|
+
);
|
|
5137
5281
|
await this.put(registered.uploadUrl, chunk.gz, registered.uploadHeaders);
|
|
5138
5282
|
await this.markUploaded(batchId, registered.chunkId);
|
|
5139
5283
|
}
|
|
5140
|
-
return {
|
|
5284
|
+
return {
|
|
5285
|
+
ordinal: chunk.ordinal,
|
|
5286
|
+
digest: chunk.digest,
|
|
5287
|
+
bytes: chunk.bytes,
|
|
5288
|
+
rows: chunk.rows,
|
|
5289
|
+
entity: chunk.entity,
|
|
5290
|
+
chunkId: registered.chunkId,
|
|
5291
|
+
uploaded: true
|
|
5292
|
+
};
|
|
5141
5293
|
}
|
|
5142
5294
|
};
|
|
5143
5295
|
}
|
|
@@ -5151,14 +5303,20 @@ function chunkLine(row, declared) {
|
|
|
5151
5303
|
tagged.set("row", row.row);
|
|
5152
5304
|
return dumps(tagged) + "\n";
|
|
5153
5305
|
}
|
|
5154
|
-
async function* buildChunks(rows, plan) {
|
|
5306
|
+
async function* buildChunks(rows, plan, ordinalStart = 0) {
|
|
5155
5307
|
let lines = [];
|
|
5156
5308
|
let rawBytes = 0;
|
|
5157
|
-
let ordinal =
|
|
5309
|
+
let ordinal = ordinalStart;
|
|
5158
5310
|
let seen = 0;
|
|
5159
5311
|
const flush2 = () => {
|
|
5160
5312
|
const raw = Buffer.concat(lines);
|
|
5161
|
-
const built = finishChunk(
|
|
5313
|
+
const built = finishChunk(
|
|
5314
|
+
ordinal++,
|
|
5315
|
+
raw,
|
|
5316
|
+
lines.length,
|
|
5317
|
+
plan.entity,
|
|
5318
|
+
seen - lines.length
|
|
5319
|
+
);
|
|
5162
5320
|
lines = [];
|
|
5163
5321
|
rawBytes = 0;
|
|
5164
5322
|
return built;
|
|
@@ -5190,7 +5348,18 @@ function finishChunk(ordinal, raw, rows, entity, firstRow = 0) {
|
|
|
5190
5348
|
function gzipDeterministic(raw, opts = {}) {
|
|
5191
5349
|
const level = opts.level ?? GZIP_LEVEL;
|
|
5192
5350
|
const name = opts.name ? Buffer.concat([Buffer.from(opts.name, "latin1"), Buffer.from([0])]) : Buffer.alloc(0);
|
|
5193
|
-
const header = Buffer.from([
|
|
5351
|
+
const header = Buffer.from([
|
|
5352
|
+
31,
|
|
5353
|
+
139,
|
|
5354
|
+
8,
|
|
5355
|
+
opts.name ? 8 : 0,
|
|
5356
|
+
0,
|
|
5357
|
+
0,
|
|
5358
|
+
0,
|
|
5359
|
+
0,
|
|
5360
|
+
level === 9 ? 2 : level === 1 ? 4 : 0,
|
|
5361
|
+
255
|
|
5362
|
+
]);
|
|
5194
5363
|
const body = (0, import_node_zlib2.deflateRawSync)(raw, { level });
|
|
5195
5364
|
const trailer = Buffer.alloc(8);
|
|
5196
5365
|
trailer.writeUInt32LE(crc32(raw), 0);
|
|
@@ -5207,7 +5376,8 @@ function crc32(data) {
|
|
|
5207
5376
|
}
|
|
5208
5377
|
}
|
|
5209
5378
|
let crc = 4294967295;
|
|
5210
|
-
for (let i = 0; i < data.length; i++)
|
|
5379
|
+
for (let i = 0; i < data.length; i++)
|
|
5380
|
+
crc = table[(crc ^ data[i]) & 255] ^ crc >>> 8;
|
|
5211
5381
|
return (crc ^ 4294967295) >>> 0;
|
|
5212
5382
|
}
|
|
5213
5383
|
var import_node_crypto9, import_node_zlib2, DEFAULT_CHUNK_BYTES, GZIP_LEVEL, chunkName, table;
|
|
@@ -5508,6 +5678,58 @@ var init_ingest = __esm({
|
|
|
5508
5678
|
}
|
|
5509
5679
|
});
|
|
5510
5680
|
|
|
5681
|
+
// src/worlds/sandbox.ts
|
|
5682
|
+
function parseSlugRef(slugRef) {
|
|
5683
|
+
const at = slugRef.indexOf("@");
|
|
5684
|
+
if (at === -1) return { slug: slugRef };
|
|
5685
|
+
return { slug: slugRef.slice(0, at), ref: slugRef.slice(at + 1) };
|
|
5686
|
+
}
|
|
5687
|
+
var sid, WorldSandboxClient;
|
|
5688
|
+
var init_sandbox = __esm({
|
|
5689
|
+
"src/worlds/sandbox.ts"() {
|
|
5690
|
+
"use strict";
|
|
5691
|
+
init_worlds();
|
|
5692
|
+
sid = encodeURIComponent;
|
|
5693
|
+
WorldSandboxClient = class {
|
|
5694
|
+
constructor(options = {}) {
|
|
5695
|
+
this.options = options;
|
|
5696
|
+
}
|
|
5697
|
+
open(target) {
|
|
5698
|
+
return apiRequest(this.options, "POST", "/api/public/benchmark-containers/sandboxes", target);
|
|
5699
|
+
}
|
|
5700
|
+
status(sandboxId) {
|
|
5701
|
+
return apiRequest(this.options, "GET", `/api/public/benchmark-containers/sandboxes/${sid(sandboxId)}`);
|
|
5702
|
+
}
|
|
5703
|
+
async read(sandboxId, filePath) {
|
|
5704
|
+
const res = await apiRequest(
|
|
5705
|
+
this.options,
|
|
5706
|
+
"GET",
|
|
5707
|
+
`/api/public/benchmark-containers/sandboxes/${sid(sandboxId)}/file?path=${encodeURIComponent(filePath)}`
|
|
5708
|
+
);
|
|
5709
|
+
return { path: res.path, size: res.size, bytes: Buffer.from(res.contentBase64, "base64") };
|
|
5710
|
+
}
|
|
5711
|
+
write(sandboxId, filePath, bytes) {
|
|
5712
|
+
return apiRequest(this.options, "PUT", `/api/public/benchmark-containers/sandboxes/${sid(sandboxId)}/file`, {
|
|
5713
|
+
path: filePath,
|
|
5714
|
+
contentBase64: bytes.toString("base64")
|
|
5715
|
+
});
|
|
5716
|
+
}
|
|
5717
|
+
exec(sandboxId, input) {
|
|
5718
|
+
return apiRequest(this.options, "POST", `/api/public/benchmark-containers/sandboxes/${sid(sandboxId)}/exec`, input);
|
|
5719
|
+
}
|
|
5720
|
+
check(sandboxId) {
|
|
5721
|
+
return apiRequest(this.options, "POST", `/api/public/benchmark-containers/sandboxes/${sid(sandboxId)}/check`, {});
|
|
5722
|
+
}
|
|
5723
|
+
commit(sandboxId, input) {
|
|
5724
|
+
return apiRequest(this.options, "POST", `/api/public/benchmark-containers/sandboxes/${sid(sandboxId)}/commit`, input);
|
|
5725
|
+
}
|
|
5726
|
+
close(sandboxId) {
|
|
5727
|
+
return apiRequest(this.options, "DELETE", `/api/public/benchmark-containers/sandboxes/${sid(sandboxId)}`);
|
|
5728
|
+
}
|
|
5729
|
+
};
|
|
5730
|
+
}
|
|
5731
|
+
});
|
|
5732
|
+
|
|
5511
5733
|
// src/worlds/index.ts
|
|
5512
5734
|
var worlds_exports = {};
|
|
5513
5735
|
__export(worlds_exports, {
|
|
@@ -5520,6 +5742,7 @@ __export(worlds_exports, {
|
|
|
5520
5742
|
EVENT_FLUSH_INTERVAL_MS: () => EVENT_FLUSH_INTERVAL_MS,
|
|
5521
5743
|
EVENT_MAX_RETRIES: () => EVENT_MAX_RETRIES,
|
|
5522
5744
|
GatewayEvalsClient: () => GatewayEvalsClient,
|
|
5745
|
+
PushSlugConflict: () => PushSlugConflict,
|
|
5523
5746
|
STRIP_PREFIX: () => STRIP_PREFIX,
|
|
5524
5747
|
SURFACE_KINDS: () => SURFACE_KINDS,
|
|
5525
5748
|
TRANSFORMS: () => TRANSFORMS,
|
|
@@ -5527,6 +5750,7 @@ __export(worlds_exports, {
|
|
|
5527
5750
|
TaskSessions: () => TaskSessions,
|
|
5528
5751
|
WHITESPACE: () => WHITESPACE,
|
|
5529
5752
|
WorldBrowser: () => WorldBrowser,
|
|
5753
|
+
WorldSandboxClient: () => WorldSandboxClient,
|
|
5530
5754
|
WorldSession: () => WorldSession,
|
|
5531
5755
|
WorldSessionCallError: () => WorldSessionCallError,
|
|
5532
5756
|
WorldSessionTimeout: () => WorldSessionTimeout,
|
|
@@ -5536,9 +5760,11 @@ __export(worlds_exports, {
|
|
|
5536
5760
|
aggregateTaskGrade: () => aggregateTaskGrade,
|
|
5537
5761
|
apiRequest: () => apiRequest,
|
|
5538
5762
|
applyTransforms: () => applyTransforms,
|
|
5763
|
+
archiveMode: () => archiveMode,
|
|
5539
5764
|
attachManifest: () => attachManifest,
|
|
5540
5765
|
attachSession: () => attachSession,
|
|
5541
5766
|
attachTask: () => attachTask,
|
|
5767
|
+
buildFileManifest: () => buildFileManifest,
|
|
5542
5768
|
buildSourceTarball: () => buildSourceTarball,
|
|
5543
5769
|
captureToolCalls: () => captureToolCalls,
|
|
5544
5770
|
collectArchiveRelPaths: () => collectArchiveRelPaths,
|
|
@@ -5550,6 +5776,7 @@ __export(worlds_exports, {
|
|
|
5550
5776
|
deleteTask: () => deleteTask,
|
|
5551
5777
|
describeWorld: () => describeWorld,
|
|
5552
5778
|
detectProvenance: () => detectProvenance,
|
|
5779
|
+
extractBundle: () => extractBundle,
|
|
5553
5780
|
getRun: () => getRun,
|
|
5554
5781
|
getTask: () => getTask,
|
|
5555
5782
|
hashForm: () => hashForm,
|
|
@@ -5570,6 +5797,8 @@ __export(worlds_exports, {
|
|
|
5570
5797
|
openSession: () => openSession,
|
|
5571
5798
|
openTask: () => openTask,
|
|
5572
5799
|
openWorld: () => openWorld,
|
|
5800
|
+
openWorldVersion: () => openWorldVersion,
|
|
5801
|
+
parseSlugRef: () => parseSlugRef,
|
|
5573
5802
|
parseToolCallRecord: () => parseToolCallRecord,
|
|
5574
5803
|
parseTransform: () => parseTransform,
|
|
5575
5804
|
parseWorldTaskRefs: () => parseWorldTaskRefs,
|
|
@@ -5586,6 +5815,7 @@ __export(worlds_exports, {
|
|
|
5586
5815
|
redactActionArgs: () => redactActionArgs,
|
|
5587
5816
|
redactionOf: () => redactionOf,
|
|
5588
5817
|
resolveBrowserMode: () => resolveBrowserMode,
|
|
5818
|
+
resolvePushSlug: () => resolvePushSlug,
|
|
5589
5819
|
roundForm: () => roundForm,
|
|
5590
5820
|
runSessions: () => runSessions,
|
|
5591
5821
|
runTask: () => runTask,
|
|
@@ -5760,9 +5990,21 @@ async function openWorld(slugRef, options = {}) {
|
|
|
5760
5990
|
const at = slugRef.indexOf("@");
|
|
5761
5991
|
const slug = at === -1 ? slugRef : slugRef.slice(0, at);
|
|
5762
5992
|
const ref = at === -1 ? null : slugRef.slice(at + 1);
|
|
5993
|
+
return resolveWorld(slugRef, slug, ref, ref ? { ref } : {}, options);
|
|
5994
|
+
}
|
|
5995
|
+
async function openWorldVersion(slug, versionId, options = {}) {
|
|
5996
|
+
return resolveWorld(
|
|
5997
|
+
`${slug}@${versionId}`,
|
|
5998
|
+
slug,
|
|
5999
|
+
null,
|
|
6000
|
+
{ versionId },
|
|
6001
|
+
options
|
|
6002
|
+
);
|
|
6003
|
+
}
|
|
6004
|
+
async function resolveWorld(slugRef, slug, ref, pin, options) {
|
|
5763
6005
|
const version = await apiRequest(options, "POST", "/api/public/benchmark-containers/resolve-version", {
|
|
5764
6006
|
slug,
|
|
5765
|
-
...
|
|
6007
|
+
...pin
|
|
5766
6008
|
});
|
|
5767
6009
|
const world = new WorldSet(
|
|
5768
6010
|
slugRef,
|
|
@@ -5801,6 +6043,7 @@ var init_worlds = __esm({
|
|
|
5801
6043
|
init_query();
|
|
5802
6044
|
init_migrate();
|
|
5803
6045
|
init_ingest();
|
|
6046
|
+
init_sandbox();
|
|
5804
6047
|
ApiError2 = class extends Error {
|
|
5805
6048
|
constructor(status, method, path14, body) {
|
|
5806
6049
|
super(`${method} ${path14} -> ${status}: ${body}`);
|
|
@@ -5908,6 +6151,7 @@ __export(src_exports, {
|
|
|
5908
6151
|
Persona: () => Persona,
|
|
5909
6152
|
PersonaError: () => PersonaError,
|
|
5910
6153
|
PersonasClient: () => PersonasClient,
|
|
6154
|
+
PushSlugConflict: () => PushSlugConflict,
|
|
5911
6155
|
REPLAY_ENVIRONMENT: () => REPLAY_ENVIRONMENT,
|
|
5912
6156
|
ReplayCase: () => ReplayCase,
|
|
5913
6157
|
ReplayCheck: () => ReplayCheck,
|
|
@@ -5934,6 +6178,7 @@ __export(src_exports, {
|
|
|
5934
6178
|
UsersClient: () => UsersClient,
|
|
5935
6179
|
WHITESPACE: () => WHITESPACE,
|
|
5936
6180
|
WorldBrowser: () => WorldBrowser,
|
|
6181
|
+
WorldSandboxClient: () => WorldSandboxClient,
|
|
5937
6182
|
WorldSession: () => WorldSession,
|
|
5938
6183
|
WorldSessionCallError: () => WorldSessionCallError,
|
|
5939
6184
|
WorldSessionTimeout: () => WorldSessionTimeout,
|
|
@@ -5944,12 +6189,14 @@ __export(src_exports, {
|
|
|
5944
6189
|
aggregateTaskGrade: () => aggregateTaskGrade,
|
|
5945
6190
|
apiRequest: () => apiRequest,
|
|
5946
6191
|
applyTransforms: () => applyTransforms,
|
|
6192
|
+
archiveMode: () => archiveMode,
|
|
5947
6193
|
assembleManifest: () => assembleManifest,
|
|
5948
6194
|
assignVariant: () => assignVariant,
|
|
5949
6195
|
attachManifest: () => attachManifest,
|
|
5950
6196
|
attachSession: () => attachSession,
|
|
5951
6197
|
attachTask: () => attachTask,
|
|
5952
6198
|
basicAuthHeader: () => basicAuthHeader,
|
|
6199
|
+
buildFileManifest: () => buildFileManifest,
|
|
5953
6200
|
buildSourceTarball: () => buildSourceTarball,
|
|
5954
6201
|
canonicalJson: () => canonicalJson,
|
|
5955
6202
|
captureToolCalls: () => captureToolCalls,
|
|
@@ -5970,6 +6217,7 @@ __export(src_exports, {
|
|
|
5970
6217
|
detectProvenance: () => detectProvenance,
|
|
5971
6218
|
experimentContextStorage: () => experimentContextStorage,
|
|
5972
6219
|
experiments: () => singleton_exports,
|
|
6220
|
+
extractBundle: () => extractBundle,
|
|
5973
6221
|
files: () => files_exports,
|
|
5974
6222
|
gateway: () => gateway,
|
|
5975
6223
|
getExperimentContext: () => getExperimentContext,
|
|
@@ -6001,6 +6249,8 @@ __export(src_exports, {
|
|
|
6001
6249
|
openSession: () => openSession,
|
|
6002
6250
|
openTask: () => openTask,
|
|
6003
6251
|
openWorld: () => openWorld,
|
|
6252
|
+
openWorldVersion: () => openWorldVersion,
|
|
6253
|
+
parseSlugRef: () => parseSlugRef,
|
|
6004
6254
|
parseToolCallRecord: () => parseToolCallRecord,
|
|
6005
6255
|
parseTransform: () => parseTransform,
|
|
6006
6256
|
parseWorldTaskRefs: () => parseWorldTaskRefs,
|
|
@@ -6024,6 +6274,7 @@ __export(src_exports, {
|
|
|
6024
6274
|
replay: () => replay,
|
|
6025
6275
|
resetBuildRegistry: () => resetBuildRegistry,
|
|
6026
6276
|
resolveBrowserMode: () => resolveBrowserMode,
|
|
6277
|
+
resolvePushSlug: () => resolvePushSlug,
|
|
6027
6278
|
resolveUserId: () => resolveUserId,
|
|
6028
6279
|
roundForm: () => roundForm,
|
|
6029
6280
|
runSessions: () => runSessions,
|
|
@@ -8739,6 +8990,7 @@ var hooks_exports = {};
|
|
|
8739
8990
|
__export(hooks_exports, {
|
|
8740
8991
|
AliasHandler: () => AliasHandler,
|
|
8741
8992
|
AliasMap: () => AliasMap,
|
|
8993
|
+
AuditReport: () => AuditReport,
|
|
8742
8994
|
CONTEXT_KEY: () => CONTEXT_KEY,
|
|
8743
8995
|
CallableTool: () => CallableTool,
|
|
8744
8996
|
CommandHandler: () => CommandHandler,
|
|
@@ -8746,6 +8998,8 @@ __export(hooks_exports, {
|
|
|
8746
8998
|
DenyHandler: () => DenyHandler,
|
|
8747
8999
|
EVENTS: () => EVENTS,
|
|
8748
9000
|
EVENT_ALIASES: () => EVENT_ALIASES,
|
|
9001
|
+
FieldSource: () => FieldSource,
|
|
9002
|
+
FinderSource: () => FinderSource,
|
|
8749
9003
|
FunctionHandler: () => FunctionHandler,
|
|
8750
9004
|
HANDLER_TYPES: () => HANDLER_TYPES,
|
|
8751
9005
|
HookConfigError: () => HookConfigError,
|
|
@@ -8757,13 +9011,18 @@ __export(hooks_exports, {
|
|
|
8757
9011
|
HttpTool: () => HttpTool,
|
|
8758
9012
|
INBOUND_KINDS: () => INBOUND_KINDS,
|
|
8759
9013
|
INPUT_TYPES: () => INPUT_TYPES,
|
|
9014
|
+
Identifier: () => Identifier,
|
|
9015
|
+
IdentifierCensus: () => IdentifierCensus,
|
|
9016
|
+
IdentifierSource: () => IdentifierSource,
|
|
8760
9017
|
KINDS: () => KINDS,
|
|
9018
|
+
LegendSource: () => LegendSource,
|
|
8761
9019
|
LiveToolError: () => LiveToolError,
|
|
8762
9020
|
LiveTools: () => LiveTools,
|
|
8763
9021
|
PARSE_MODES: () => PARSE_MODES,
|
|
8764
9022
|
RecordHandler: () => RecordHandler,
|
|
8765
9023
|
Recorder: () => Recorder,
|
|
8766
9024
|
RedactHandler: () => RedactHandler,
|
|
9025
|
+
RedactionAudit: () => RedactionAudit,
|
|
8767
9026
|
Replay: () => Replay,
|
|
8768
9027
|
TOOL_KINDS: () => TOOL_KINDS,
|
|
8769
9028
|
applyLimit: () => applyLimit,
|
|
@@ -8818,6 +9077,49 @@ __export(hooks_exports, {
|
|
|
8818
9077
|
withDefaults: () => withDefaults
|
|
8819
9078
|
});
|
|
8820
9079
|
|
|
9080
|
+
// src/hooks/caseSwap.ts
|
|
9081
|
+
var CASE_SWAP_MIN_CHARS = 4;
|
|
9082
|
+
var standingAlone = /* @__PURE__ */ new Map();
|
|
9083
|
+
function standingAlonePattern(needle) {
|
|
9084
|
+
let pattern = standingAlone.get(needle);
|
|
9085
|
+
if (pattern === void 0) {
|
|
9086
|
+
const escaped = needle.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
9087
|
+
pattern = new RegExp(`(?<![A-Za-z0-9])${escaped}(?![A-Za-z0-9])`, "gi");
|
|
9088
|
+
standingAlone.set(needle, pattern);
|
|
9089
|
+
}
|
|
9090
|
+
return pattern;
|
|
9091
|
+
}
|
|
9092
|
+
var WORD = /[A-Za-z0-9]+/g;
|
|
9093
|
+
function shapedWord(word, seen) {
|
|
9094
|
+
const hasLetter = seen.toLowerCase() !== seen.toUpperCase();
|
|
9095
|
+
if (hasLetter && seen === seen.toUpperCase()) return word.toUpperCase();
|
|
9096
|
+
if (hasLetter && seen === seen.toLowerCase()) return word.toLowerCase();
|
|
9097
|
+
const first = seen.slice(0, 1);
|
|
9098
|
+
if (first !== first.toLowerCase())
|
|
9099
|
+
return word.slice(0, 1).toUpperCase() + word.slice(1);
|
|
9100
|
+
return word;
|
|
9101
|
+
}
|
|
9102
|
+
function shaped(replacement, seen) {
|
|
9103
|
+
const seenWords = seen.match(WORD) ?? [];
|
|
9104
|
+
if (seenWords.length !== (replacement.match(WORD) ?? []).length)
|
|
9105
|
+
return shapedWord(replacement, seen);
|
|
9106
|
+
let index2 = 0;
|
|
9107
|
+
return replacement.replace(
|
|
9108
|
+
WORD,
|
|
9109
|
+
(word) => shapedWord(word, seenWords[index2++])
|
|
9110
|
+
);
|
|
9111
|
+
}
|
|
9112
|
+
function swapValue(text2, needle, replacement) {
|
|
9113
|
+
if (!needle) return text2;
|
|
9114
|
+
const out = text2.split(needle).join(replacement);
|
|
9115
|
+
if (needle.length < CASE_SWAP_MIN_CHARS) return out;
|
|
9116
|
+
if (!out.toLowerCase().includes(needle.toLowerCase())) return out;
|
|
9117
|
+
return out.replace(
|
|
9118
|
+
standingAlonePattern(needle),
|
|
9119
|
+
(seen) => shaped(replacement, seen)
|
|
9120
|
+
);
|
|
9121
|
+
}
|
|
9122
|
+
|
|
8821
9123
|
// src/hooks/alias.ts
|
|
8822
9124
|
var import_node_crypto11 = require("crypto");
|
|
8823
9125
|
var GIVEN = [
|
|
@@ -9652,10 +9954,9 @@ var AliasMap = class _AliasMap {
|
|
|
9652
9954
|
const [inbound] = this.pairs();
|
|
9653
9955
|
let out = text2;
|
|
9654
9956
|
for (const [needle, replacement, alias] of inbound) {
|
|
9655
|
-
|
|
9656
|
-
|
|
9657
|
-
|
|
9658
|
-
}
|
|
9957
|
+
const swapped = swapValue(out, needle, replacement);
|
|
9958
|
+
if (swapped !== out) alias.hitsIn += 1;
|
|
9959
|
+
out = swapped;
|
|
9659
9960
|
}
|
|
9660
9961
|
out = out.replace(SHA256_ANY_GLOBAL, (match) => this.mintDigest(match));
|
|
9661
9962
|
if (this.mintInbound.length) out = this.mintFoundIn(out, where);
|
|
@@ -9671,10 +9972,9 @@ var AliasMap = class _AliasMap {
|
|
|
9671
9972
|
const [, outbound] = this.pairs();
|
|
9672
9973
|
let out = text2;
|
|
9673
9974
|
for (const [needle, replacement, alias] of outbound) {
|
|
9674
|
-
|
|
9675
|
-
|
|
9676
|
-
|
|
9677
|
-
}
|
|
9975
|
+
const swapped = swapValue(out, needle, replacement);
|
|
9976
|
+
if (swapped !== out) alias.hitsOut += 1;
|
|
9977
|
+
out = swapped;
|
|
9678
9978
|
}
|
|
9679
9979
|
const problems = [];
|
|
9680
9980
|
for (const [needle] of outbound) {
|
|
@@ -12310,6 +12610,221 @@ var LiveTools = class _LiveTools {
|
|
|
12310
12610
|
}
|
|
12311
12611
|
};
|
|
12312
12612
|
|
|
12613
|
+
// src/hooks/audit.ts
|
|
12614
|
+
var MIN_VALUE_CHARS = 4;
|
|
12615
|
+
var REVIEW_MIN_CHARS = 20;
|
|
12616
|
+
var ANY_TOOL = "*";
|
|
12617
|
+
var isObject6 = (node) => typeof node === "object" && node !== null && !Array.isArray(node);
|
|
12618
|
+
function* stringsOf(node) {
|
|
12619
|
+
if (typeof node === "string") {
|
|
12620
|
+
yield node;
|
|
12621
|
+
return;
|
|
12622
|
+
}
|
|
12623
|
+
const children = Array.isArray(node) ? node : isObject6(node) ? Object.values(node) : [];
|
|
12624
|
+
for (const child of children) yield* stringsOf(child);
|
|
12625
|
+
}
|
|
12626
|
+
function* fieldsOf(node) {
|
|
12627
|
+
if (Array.isArray(node)) {
|
|
12628
|
+
for (const child of node) yield* fieldsOf(child);
|
|
12629
|
+
return;
|
|
12630
|
+
}
|
|
12631
|
+
if (!isObject6(node)) return;
|
|
12632
|
+
for (const [key2, value] of Object.entries(node)) {
|
|
12633
|
+
yield [key2, value];
|
|
12634
|
+
yield* fieldsOf(value);
|
|
12635
|
+
}
|
|
12636
|
+
}
|
|
12637
|
+
var Identifier = class {
|
|
12638
|
+
constructor(kind, value, source) {
|
|
12639
|
+
this.kind = kind;
|
|
12640
|
+
this.value = value;
|
|
12641
|
+
this.source = source;
|
|
12642
|
+
}
|
|
12643
|
+
get key() {
|
|
12644
|
+
return folded(this.value);
|
|
12645
|
+
}
|
|
12646
|
+
get prefix() {
|
|
12647
|
+
return this.value.slice(0, 3);
|
|
12648
|
+
}
|
|
12649
|
+
};
|
|
12650
|
+
var IdentifierSource = class {
|
|
12651
|
+
ignored() {
|
|
12652
|
+
return [];
|
|
12653
|
+
}
|
|
12654
|
+
};
|
|
12655
|
+
var LegendSource = class extends IdentifierSource {
|
|
12656
|
+
name = "legend";
|
|
12657
|
+
entries;
|
|
12658
|
+
constructor(legend) {
|
|
12659
|
+
super();
|
|
12660
|
+
this.entries = legend.filter((entry) => entry.real);
|
|
12661
|
+
}
|
|
12662
|
+
collect() {
|
|
12663
|
+
return this.entries.filter((entry) => (entry.role ?? "private") !== "public").map((entry) => new Identifier(entry.kind ?? "reference", String(entry.real), this.name));
|
|
12664
|
+
}
|
|
12665
|
+
ignored() {
|
|
12666
|
+
const open = this.entries.filter((e) => e.role === "public").map((e) => String(e.real));
|
|
12667
|
+
const personas2 = this.entries.filter((e) => e.alias).map((e) => String(e.alias));
|
|
12668
|
+
return [...open, ...personas2];
|
|
12669
|
+
}
|
|
12670
|
+
};
|
|
12671
|
+
var FieldSource = class extends IdentifierSource {
|
|
12672
|
+
constructor(fieldKinds) {
|
|
12673
|
+
super();
|
|
12674
|
+
this.fieldKinds = fieldKinds;
|
|
12675
|
+
}
|
|
12676
|
+
name = "fields";
|
|
12677
|
+
kindsFor(tool) {
|
|
12678
|
+
return { ...this.fieldKinds[ANY_TOOL] ?? {}, ...this.fieldKinds[tool] ?? {} };
|
|
12679
|
+
}
|
|
12680
|
+
*collect(raw) {
|
|
12681
|
+
for (const record of raw) {
|
|
12682
|
+
const kinds = this.kindsFor(String(record.tool ?? ""));
|
|
12683
|
+
for (const [key2, value] of fieldsOf(record.result)) {
|
|
12684
|
+
const kind = kinds[key2];
|
|
12685
|
+
if (kind === void 0) continue;
|
|
12686
|
+
for (const text2 of stringsOf(value)) yield new Identifier(kind, text2, this.name);
|
|
12687
|
+
}
|
|
12688
|
+
}
|
|
12689
|
+
}
|
|
12690
|
+
};
|
|
12691
|
+
var FinderSource = class extends IdentifierSource {
|
|
12692
|
+
name;
|
|
12693
|
+
kinds;
|
|
12694
|
+
constructor(kinds = INBOUND_KINDS) {
|
|
12695
|
+
super();
|
|
12696
|
+
const bad = kinds.filter((kind) => !INBOUND_KINDS.includes(kind));
|
|
12697
|
+
if (bad.length > 0)
|
|
12698
|
+
throw new Error(
|
|
12699
|
+
`${bad.join(", ")} cannot be found by a pattern; only ${INBOUND_KINDS.join(", ")} can`
|
|
12700
|
+
);
|
|
12701
|
+
this.kinds = [...kinds];
|
|
12702
|
+
this.name = `finders:${this.kinds.join(",")}`;
|
|
12703
|
+
}
|
|
12704
|
+
*collect(raw) {
|
|
12705
|
+
for (const record of raw)
|
|
12706
|
+
for (const text2 of stringsOf(record.result))
|
|
12707
|
+
for (const kind of this.kinds)
|
|
12708
|
+
for (const value of findKind(kind, text2)) yield new Identifier(kind, value, "finders");
|
|
12709
|
+
}
|
|
12710
|
+
};
|
|
12711
|
+
var IdentifierCensus = class {
|
|
12712
|
+
constructor(sources) {
|
|
12713
|
+
this.sources = sources;
|
|
12714
|
+
}
|
|
12715
|
+
get detectors() {
|
|
12716
|
+
return this.sources.map((source) => source.name);
|
|
12717
|
+
}
|
|
12718
|
+
build(raw) {
|
|
12719
|
+
const ignored = new Set(this.sources.flatMap((s) => [...s.ignored()].map(folded)));
|
|
12720
|
+
const seen = /* @__PURE__ */ new Map();
|
|
12721
|
+
for (const source of this.sources)
|
|
12722
|
+
for (const identifier of source.collect(raw)) {
|
|
12723
|
+
if (identifier.value.length < MIN_VALUE_CHARS || ignored.has(identifier.key)) continue;
|
|
12724
|
+
if (!seen.has(identifier.key)) seen.set(identifier.key, identifier);
|
|
12725
|
+
}
|
|
12726
|
+
return [...seen.values()];
|
|
12727
|
+
}
|
|
12728
|
+
};
|
|
12729
|
+
function shuffled(items, seed) {
|
|
12730
|
+
const out = [...items];
|
|
12731
|
+
let state2 = seed >>> 0;
|
|
12732
|
+
const next = () => {
|
|
12733
|
+
state2 = state2 + 1831565813 >>> 0;
|
|
12734
|
+
let t = Math.imul(state2 ^ state2 >>> 15, 1 | state2);
|
|
12735
|
+
t = t + Math.imul(t ^ t >>> 7, 61 | t) ^ t;
|
|
12736
|
+
return ((t ^ t >>> 14) >>> 0) / 4294967296;
|
|
12737
|
+
};
|
|
12738
|
+
for (let i = out.length - 1; i > 0; i -= 1) {
|
|
12739
|
+
const j = Math.floor(next() * (i + 1));
|
|
12740
|
+
[out[i], out[j]] = [out[j], out[i]];
|
|
12741
|
+
}
|
|
12742
|
+
return out;
|
|
12743
|
+
}
|
|
12744
|
+
var AuditReport = class {
|
|
12745
|
+
constructor(findings, census, detectors, recordsScanned, leakedIdentifiers, cleanTexts) {
|
|
12746
|
+
this.findings = findings;
|
|
12747
|
+
this.census = census;
|
|
12748
|
+
this.detectors = detectors;
|
|
12749
|
+
this.recordsScanned = recordsScanned;
|
|
12750
|
+
this.leakedIdentifiers = leakedIdentifiers;
|
|
12751
|
+
this.cleanTexts = cleanTexts;
|
|
12752
|
+
}
|
|
12753
|
+
get ok() {
|
|
12754
|
+
return this.findings.length === 0;
|
|
12755
|
+
}
|
|
12756
|
+
get censusTotal() {
|
|
12757
|
+
return this.census.length;
|
|
12758
|
+
}
|
|
12759
|
+
/** The share of census identifiers that did NOT reach the model; 1 for an empty census. */
|
|
12760
|
+
get coverage() {
|
|
12761
|
+
if (this.census.length === 0) return 1;
|
|
12762
|
+
return Math.round((1 - this.leakedIdentifiers / this.census.length) * 1e4) / 1e4;
|
|
12763
|
+
}
|
|
12764
|
+
count(pick3) {
|
|
12765
|
+
const counts = {};
|
|
12766
|
+
for (const identifier of this.census) counts[pick3(identifier)] = (counts[pick3(identifier)] ?? 0) + 1;
|
|
12767
|
+
return counts;
|
|
12768
|
+
}
|
|
12769
|
+
/** `size` strings the model saw that nothing flagged, for a person to read. */
|
|
12770
|
+
reviewSample(size, seed = 0) {
|
|
12771
|
+
const pool = [...this.cleanTexts].sort(
|
|
12772
|
+
(a, b) => a.record - b.record || a.text.localeCompare(b.text)
|
|
12773
|
+
);
|
|
12774
|
+
return shuffled(pool, seed).slice(0, size);
|
|
12775
|
+
}
|
|
12776
|
+
toDict() {
|
|
12777
|
+
return {
|
|
12778
|
+
ok: this.ok,
|
|
12779
|
+
records_scanned: this.recordsScanned,
|
|
12780
|
+
detectors: this.detectors,
|
|
12781
|
+
census: {
|
|
12782
|
+
total: this.censusTotal,
|
|
12783
|
+
by_source: this.count((i) => i.source),
|
|
12784
|
+
by_kind: this.count((i) => i.kind)
|
|
12785
|
+
},
|
|
12786
|
+
leaked_identifiers: this.leakedIdentifiers,
|
|
12787
|
+
coverage: this.coverage,
|
|
12788
|
+
findings: this.findings
|
|
12789
|
+
};
|
|
12790
|
+
}
|
|
12791
|
+
};
|
|
12792
|
+
var RedactionAudit = class _RedactionAudit {
|
|
12793
|
+
constructor(census) {
|
|
12794
|
+
this.census = census;
|
|
12795
|
+
}
|
|
12796
|
+
/** The standard audit: the run's legend, declared field kinds, pattern finders. */
|
|
12797
|
+
static forRun(options) {
|
|
12798
|
+
return new _RedactionAudit(
|
|
12799
|
+
new IdentifierCensus([
|
|
12800
|
+
new LegendSource(options.legend ?? []),
|
|
12801
|
+
new FieldSource(options.fieldKinds ?? {}),
|
|
12802
|
+
new FinderSource(options.finderKinds ?? INBOUND_KINDS)
|
|
12803
|
+
])
|
|
12804
|
+
);
|
|
12805
|
+
}
|
|
12806
|
+
run(raw, shown) {
|
|
12807
|
+
const census = this.census.build(raw);
|
|
12808
|
+
const findings = [];
|
|
12809
|
+
const clean = [];
|
|
12810
|
+
const leaked = /* @__PURE__ */ new Set();
|
|
12811
|
+
shown.forEach((record, index2) => {
|
|
12812
|
+
const tool = String(record.tool ?? "");
|
|
12813
|
+
const texts = [...stringsOf(record.result)];
|
|
12814
|
+
const haystack = folded(texts.join("\n"));
|
|
12815
|
+
const hits = census.filter((identifier) => haystack.includes(identifier.key));
|
|
12816
|
+
hits.forEach((identifier) => leaked.add(identifier.key));
|
|
12817
|
+
findings.push(
|
|
12818
|
+
...hits.map((i) => ({ record: index2, tool, kind: i.kind, source: i.source, prefix: i.prefix }))
|
|
12819
|
+
);
|
|
12820
|
+
clean.push(
|
|
12821
|
+
...texts.filter((t) => t.length >= REVIEW_MIN_CHARS && !hits.some((i) => folded(t).includes(i.key))).map((text2) => ({ record: index2, tool, text: text2 }))
|
|
12822
|
+
);
|
|
12823
|
+
});
|
|
12824
|
+
return new AuditReport(findings, census, this.census.detectors, shown.length, leaked.size, clean);
|
|
12825
|
+
}
|
|
12826
|
+
};
|
|
12827
|
+
|
|
12313
12828
|
// src/hooks/run.ts
|
|
12314
12829
|
var import_node_crypto12 = require("crypto");
|
|
12315
12830
|
var fs15 = __toESM(require("fs"));
|
|
@@ -13093,10 +13608,28 @@ function toolResultText(content) {
|
|
|
13093
13608
|
).join("");
|
|
13094
13609
|
return JSON.stringify(content ?? "");
|
|
13095
13610
|
}
|
|
13611
|
+
function toolSummary(names) {
|
|
13612
|
+
return names.map((n) => `\u2192 ${n}`).join(", ");
|
|
13613
|
+
}
|
|
13614
|
+
var USAGE_ATTRIBUTES = [
|
|
13615
|
+
["input_tokens", "llm.token_count.prompt"],
|
|
13616
|
+
["output_tokens", "llm.token_count.completion"],
|
|
13617
|
+
["cache_read_input_tokens", "llm.token_count.prompt_details.cache_read"],
|
|
13618
|
+
["cache_creation_input_tokens", "llm.token_count.prompt_details.cache_write"]
|
|
13619
|
+
];
|
|
13620
|
+
function setUsageAttributes(span, usage) {
|
|
13621
|
+
if (!usage || typeof usage !== "object") return;
|
|
13622
|
+
const u = usage;
|
|
13623
|
+
for (const [field, attribute] of USAGE_ATTRIBUTES) {
|
|
13624
|
+
const value = u[field];
|
|
13625
|
+
if (typeof value === "number" && Number.isFinite(value))
|
|
13626
|
+
span.setAttribute(attribute, value);
|
|
13627
|
+
}
|
|
13628
|
+
}
|
|
13096
13629
|
var TURN_INPUT_MAX = 4e3;
|
|
13097
13630
|
async function* observeClaude(stream, options) {
|
|
13098
13631
|
const tracer = options.tracer ?? import_api4.trace.getTracer("@withgateway/sdk");
|
|
13099
|
-
const
|
|
13632
|
+
const fallbackModel = options.model ?? "claude";
|
|
13100
13633
|
const openTools = /* @__PURE__ */ new Map();
|
|
13101
13634
|
let root = null;
|
|
13102
13635
|
let rootCtx = null;
|
|
@@ -13114,85 +13647,102 @@ async function* observeClaude(stream, options) {
|
|
|
13114
13647
|
let turnCtx = null;
|
|
13115
13648
|
let turnIndex = 0;
|
|
13116
13649
|
let turnText = "";
|
|
13650
|
+
let turnTools = [];
|
|
13117
13651
|
let pendingTurnInput = options.input ?? "";
|
|
13652
|
+
let gen = null;
|
|
13653
|
+
let genMessageId;
|
|
13654
|
+
let genText = "";
|
|
13655
|
+
let genTools = [];
|
|
13656
|
+
let genUsage;
|
|
13118
13657
|
let finalText = "";
|
|
13658
|
+
const endGeneration = () => {
|
|
13659
|
+
if (!gen) return;
|
|
13660
|
+
gen.setAttribute("output.value", genText || toolSummary(genTools));
|
|
13661
|
+
setUsageAttributes(gen, genUsage);
|
|
13662
|
+
gen.setStatus({ code: import_api4.SpanStatusCode.OK });
|
|
13663
|
+
gen.end();
|
|
13664
|
+
gen = null;
|
|
13665
|
+
genMessageId = void 0;
|
|
13666
|
+
genText = "";
|
|
13667
|
+
genTools = [];
|
|
13668
|
+
genUsage = void 0;
|
|
13669
|
+
};
|
|
13119
13670
|
const endTurn = () => {
|
|
13120
13671
|
if (!turnRoot) return;
|
|
13121
|
-
|
|
13672
|
+
const output = turnText || toolSummary(turnTools);
|
|
13673
|
+
if (output) turnRoot.setAttribute("output.value", output);
|
|
13122
13674
|
turnRoot.setStatus({ code: import_api4.SpanStatusCode.OK });
|
|
13123
13675
|
turnRoot.end();
|
|
13124
13676
|
turnRoot = null;
|
|
13125
13677
|
turnCtx = null;
|
|
13126
13678
|
};
|
|
13679
|
+
const startTurn = () => {
|
|
13680
|
+
for (const span of openTools.values()) span.end();
|
|
13681
|
+
openTools.clear();
|
|
13682
|
+
endTurn();
|
|
13683
|
+
turnIndex += 1;
|
|
13684
|
+
turnText = "";
|
|
13685
|
+
turnTools = [];
|
|
13686
|
+
turnRoot = tracer.startSpan(`${options.name} \xB7 turn ${turnIndex}`, {
|
|
13687
|
+
root: true,
|
|
13688
|
+
attributes: {
|
|
13689
|
+
"openinference.span.kind": "AGENT",
|
|
13690
|
+
...pendingTurnInput ? { "input.value": pendingTurnInput.slice(0, TURN_INPUT_MAX) } : {},
|
|
13691
|
+
...options.attributes ?? {}
|
|
13692
|
+
}
|
|
13693
|
+
});
|
|
13694
|
+
turnCtx = import_api4.trace.setSpan(import_api4.context.active(), turnRoot);
|
|
13695
|
+
pendingTurnInput = "";
|
|
13696
|
+
};
|
|
13697
|
+
const startGeneration = (message) => {
|
|
13698
|
+
endGeneration();
|
|
13699
|
+
if (options.perTurn) startTurn();
|
|
13700
|
+
const childCtx = options.perTurn ? turnCtx : rootCtx;
|
|
13701
|
+
genMessageId = message.message?.id;
|
|
13702
|
+
gen = tracer.startSpan(
|
|
13703
|
+
"assistant",
|
|
13704
|
+
{
|
|
13705
|
+
attributes: {
|
|
13706
|
+
"openinference.span.kind": "LLM",
|
|
13707
|
+
"llm.model_name": message.message?.model ?? fallbackModel,
|
|
13708
|
+
"llm.provider": "anthropic"
|
|
13709
|
+
}
|
|
13710
|
+
},
|
|
13711
|
+
childCtx
|
|
13712
|
+
);
|
|
13713
|
+
};
|
|
13127
13714
|
try {
|
|
13128
13715
|
for await (const message of stream) {
|
|
13129
13716
|
if (message?.type === "assistant") {
|
|
13130
|
-
|
|
13131
|
-
|
|
13132
|
-
|
|
13133
|
-
endTurn();
|
|
13134
|
-
turnIndex += 1;
|
|
13135
|
-
turnText = "";
|
|
13136
|
-
turnRoot = tracer.startSpan(`${options.name} \xB7 turn ${turnIndex}`, {
|
|
13137
|
-
root: true,
|
|
13138
|
-
attributes: {
|
|
13139
|
-
"openinference.span.kind": "AGENT",
|
|
13140
|
-
...pendingTurnInput ? { "input.value": pendingTurnInput.slice(0, TURN_INPUT_MAX) } : {},
|
|
13141
|
-
...options.attributes ?? {}
|
|
13142
|
-
}
|
|
13143
|
-
});
|
|
13144
|
-
turnCtx = import_api4.trace.setSpan(import_api4.context.active(), turnRoot);
|
|
13145
|
-
pendingTurnInput = "";
|
|
13146
|
-
}
|
|
13717
|
+
const messageId = message.message?.id;
|
|
13718
|
+
const continuesGeneration = gen !== null && messageId !== void 0 && messageId === genMessageId;
|
|
13719
|
+
if (!continuesGeneration) startGeneration(message);
|
|
13147
13720
|
const childCtx = options.perTurn ? turnCtx : rootCtx;
|
|
13148
|
-
let text2 = "";
|
|
13149
|
-
const toolUses = [];
|
|
13150
13721
|
for (const block of message.message?.content ?? []) {
|
|
13151
13722
|
if (block?.type === "text") {
|
|
13152
13723
|
finalText += block.text;
|
|
13153
|
-
|
|
13724
|
+
turnText += block.text;
|
|
13725
|
+
genText += block.text;
|
|
13154
13726
|
}
|
|
13155
13727
|
if (block?.type === "tool_use") {
|
|
13156
|
-
|
|
13157
|
-
|
|
13158
|
-
|
|
13159
|
-
|
|
13160
|
-
|
|
13728
|
+
const name = cleanToolName(block.name);
|
|
13729
|
+
genTools.push(name);
|
|
13730
|
+
turnTools.push(name);
|
|
13731
|
+
const span = tracer.startSpan(
|
|
13732
|
+
`tool.${name}`,
|
|
13733
|
+
{
|
|
13734
|
+
attributes: {
|
|
13735
|
+
"openinference.span.kind": "TOOL",
|
|
13736
|
+
"tool.name": name,
|
|
13737
|
+
"input.value": JSON.stringify(block.input)
|
|
13738
|
+
}
|
|
13739
|
+
},
|
|
13740
|
+
childCtx
|
|
13741
|
+
);
|
|
13742
|
+
openTools.set(block.id, span);
|
|
13161
13743
|
}
|
|
13162
13744
|
}
|
|
13163
|
-
|
|
13164
|
-
const gen = tracer.startSpan(
|
|
13165
|
-
"assistant",
|
|
13166
|
-
{
|
|
13167
|
-
attributes: {
|
|
13168
|
-
"openinference.span.kind": "LLM",
|
|
13169
|
-
"llm.model_name": model,
|
|
13170
|
-
"llm.provider": "anthropic",
|
|
13171
|
-
"output.value": text2 || toolUses.map((t) => `\u2192 ${cleanToolName(t.name)}`).join(", ")
|
|
13172
|
-
}
|
|
13173
|
-
},
|
|
13174
|
-
childCtx
|
|
13175
|
-
);
|
|
13176
|
-
const usage = message.message?.usage;
|
|
13177
|
-
if (usage?.input_tokens != null)
|
|
13178
|
-
gen.setAttribute("llm.token_count.prompt", usage.input_tokens);
|
|
13179
|
-
if (usage?.output_tokens != null)
|
|
13180
|
-
gen.setAttribute("llm.token_count.completion", usage.output_tokens);
|
|
13181
|
-
gen.end();
|
|
13182
|
-
for (const t of toolUses) {
|
|
13183
|
-
const span = tracer.startSpan(
|
|
13184
|
-
`tool.${cleanToolName(t.name)}`,
|
|
13185
|
-
{
|
|
13186
|
-
attributes: {
|
|
13187
|
-
"openinference.span.kind": "TOOL",
|
|
13188
|
-
"tool.name": cleanToolName(t.name),
|
|
13189
|
-
"input.value": JSON.stringify(t.input)
|
|
13190
|
-
}
|
|
13191
|
-
},
|
|
13192
|
-
childCtx
|
|
13193
|
-
);
|
|
13194
|
-
openTools.set(t.id, span);
|
|
13195
|
-
}
|
|
13745
|
+
if (message.message?.usage) genUsage = message.message.usage;
|
|
13196
13746
|
}
|
|
13197
13747
|
if (message?.type === "user") {
|
|
13198
13748
|
const content = message.message?.content;
|
|
@@ -13217,6 +13767,7 @@ async function* observeClaude(stream, options) {
|
|
|
13217
13767
|
yield message;
|
|
13218
13768
|
}
|
|
13219
13769
|
} finally {
|
|
13770
|
+
endGeneration();
|
|
13220
13771
|
for (const span of openTools.values()) span.end();
|
|
13221
13772
|
openTools.clear();
|
|
13222
13773
|
if (options.perTurn) {
|
|
@@ -13280,6 +13831,7 @@ var tracing = {
|
|
|
13280
13831
|
Persona,
|
|
13281
13832
|
PersonaError,
|
|
13282
13833
|
PersonasClient,
|
|
13834
|
+
PushSlugConflict,
|
|
13283
13835
|
REPLAY_ENVIRONMENT,
|
|
13284
13836
|
ReplayCase,
|
|
13285
13837
|
ReplayCheck,
|
|
@@ -13306,6 +13858,7 @@ var tracing = {
|
|
|
13306
13858
|
UsersClient,
|
|
13307
13859
|
WHITESPACE,
|
|
13308
13860
|
WorldBrowser,
|
|
13861
|
+
WorldSandboxClient,
|
|
13309
13862
|
WorldSession,
|
|
13310
13863
|
WorldSessionCallError,
|
|
13311
13864
|
WorldSessionTimeout,
|
|
@@ -13316,12 +13869,14 @@ var tracing = {
|
|
|
13316
13869
|
aggregateTaskGrade,
|
|
13317
13870
|
apiRequest,
|
|
13318
13871
|
applyTransforms,
|
|
13872
|
+
archiveMode,
|
|
13319
13873
|
assembleManifest,
|
|
13320
13874
|
assignVariant,
|
|
13321
13875
|
attachManifest,
|
|
13322
13876
|
attachSession,
|
|
13323
13877
|
attachTask,
|
|
13324
13878
|
basicAuthHeader,
|
|
13879
|
+
buildFileManifest,
|
|
13325
13880
|
buildSourceTarball,
|
|
13326
13881
|
canonicalJson,
|
|
13327
13882
|
captureToolCalls,
|
|
@@ -13342,6 +13897,7 @@ var tracing = {
|
|
|
13342
13897
|
detectProvenance,
|
|
13343
13898
|
experimentContextStorage,
|
|
13344
13899
|
experiments,
|
|
13900
|
+
extractBundle,
|
|
13345
13901
|
files,
|
|
13346
13902
|
gateway,
|
|
13347
13903
|
getExperimentContext,
|
|
@@ -13373,6 +13929,8 @@ var tracing = {
|
|
|
13373
13929
|
openSession,
|
|
13374
13930
|
openTask,
|
|
13375
13931
|
openWorld,
|
|
13932
|
+
openWorldVersion,
|
|
13933
|
+
parseSlugRef,
|
|
13376
13934
|
parseToolCallRecord,
|
|
13377
13935
|
parseTransform,
|
|
13378
13936
|
parseWorldTaskRefs,
|
|
@@ -13396,6 +13954,7 @@ var tracing = {
|
|
|
13396
13954
|
replay,
|
|
13397
13955
|
resetBuildRegistry,
|
|
13398
13956
|
resolveBrowserMode,
|
|
13957
|
+
resolvePushSlug,
|
|
13399
13958
|
resolveUserId,
|
|
13400
13959
|
roundForm,
|
|
13401
13960
|
runSessions,
|