@withgateway/sdk 0.2.9 → 0.3.0
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 +2355 -486
- package/dist/cli.js.map +1 -1
- package/dist/cli.mjs +2335 -466
- package/dist/cli.mjs.map +1 -1
- package/dist/files/index.d.mts +1 -0
- package/dist/files/index.d.ts +1 -0
- package/dist/files/index.js +1324 -21
- package/dist/files/index.js.map +1 -1
- package/dist/files/index.mjs +1322 -13
- package/dist/files/index.mjs.map +1 -1
- package/dist/{index-Cz8Q6Keo.d.mts → index-D6oi1TWE.d.mts} +93 -34
- package/dist/{index-BO2SNSgy.d.ts → index-DAb-FCMg.d.ts} +93 -34
- package/dist/index.d.mts +4 -3
- package/dist/index.d.ts +4 -3
- package/dist/index.js +1758 -116
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1720 -97
- package/dist/index.mjs.map +1 -1
- package/dist/media-CbcAfQvd.d.mts +83 -0
- package/dist/media-CbcAfQvd.d.ts +83 -0
- package/dist/traces/index.d.mts +1 -0
- package/dist/traces/index.d.ts +1 -0
- package/dist/traces/index.js +1321 -18
- package/dist/traces/index.js.map +1 -1
- package/dist/traces/index.mjs +1319 -10
- package/dist/traces/index.mjs.map +1 -1
- package/dist/tracing/index.d.mts +2 -1
- package/dist/tracing/index.d.ts +2 -1
- package/dist/tracing/index.js +512 -11
- package/dist/tracing/index.js.map +1 -1
- package/dist/tracing/index.mjs +501 -10
- package/dist/tracing/index.mjs.map +1 -1
- package/dist/worlds/index.d.mts +583 -63
- package/dist/worlds/index.d.ts +583 -63
- package/dist/worlds/index.js +1703 -94
- package/dist/worlds/index.js.map +1 -1
- package/dist/worlds/index.mjs +1689 -80
- package/dist/worlds/index.mjs.map +1 -1
- package/package.json +1 -1
- package/runtime/gatewaysdk/environment/schema/api.py +38 -56
- package/runtime/gatewaysdk/environment/schema/grading.py +1 -5
- package/runtime/gatewaysdk/environment/schema/host.py +53 -90
- package/runtime/gatewaysdk/environment/schema/local.py +15 -7
- package/runtime/gatewaysdk/environment/schema/runtime.py +9 -9
- package/runtime/gatewaysdk/environment/schema/skills/worlds-getting-started/SKILL.md +7 -7
- package/runtime/gatewaysdk/environment/schema/skills/worlds-getting-started/references/cli-mcp-map.md +1 -0
- package/runtime/gatewaysdk/environment/schema/tasks.py +25 -1
- package/skills/worlds-getting-started/SKILL.md +7 -7
- package/skills/worlds-getting-started/references/cli-mcp-map.md +1 -0
package/dist/cli.js
CHANGED
|
@@ -109,10 +109,10 @@ function parseArgs(spec, argv) {
|
|
|
109
109
|
else if (f.default !== void 0) flags[f.name] = f.default;
|
|
110
110
|
}
|
|
111
111
|
const specs4 = spec.positionals ?? [];
|
|
112
|
-
const
|
|
113
|
-
if (positionals.length <
|
|
112
|
+
const required2 = specs4.filter((p) => !p.optional && !p.variadic).length;
|
|
113
|
+
if (positionals.length < required2)
|
|
114
114
|
throw new CliError(
|
|
115
|
-
`${spec.name} needs ${specs4.slice(0,
|
|
115
|
+
`${spec.name} needs ${specs4.slice(0, required2).map((p) => `<${p.name}>`).join(" ")}`
|
|
116
116
|
);
|
|
117
117
|
const variadic = specs4.some((p) => p.variadic);
|
|
118
118
|
if (!variadic && positionals.length > specs4.length)
|
|
@@ -585,7 +585,7 @@ function withoutUiToken(url) {
|
|
|
585
585
|
const [beforeHash, hash] = splitHash(url);
|
|
586
586
|
const q = beforeHash.indexOf("?");
|
|
587
587
|
if (q < 0) return url;
|
|
588
|
-
const kept = beforeHash.slice(q + 1).split("&").filter((
|
|
588
|
+
const kept = beforeHash.slice(q + 1).split("&").filter((pair3) => pair3 !== "" && pair3.split("=")[0] !== UI_TOKEN_QUERY);
|
|
589
589
|
return beforeHash.slice(0, q) + (kept.length ? `?${kept.join("&")}` : "") + hash;
|
|
590
590
|
}
|
|
591
591
|
function splitHash(url) {
|
|
@@ -720,7 +720,7 @@ var SURFACE_KINDS, BROWSER_TIERS, DEFAULT_VIEWPORT, SETTLE_TIMEOUT_MS, SETTLE_QU
|
|
|
720
720
|
var init_browser = __esm({
|
|
721
721
|
"src/worlds/browser.ts"() {
|
|
722
722
|
"use strict";
|
|
723
|
-
|
|
723
|
+
init_session2();
|
|
724
724
|
init_browserReconnect();
|
|
725
725
|
SURFACE_KINDS = ["tools", "api", "ui", "browser"];
|
|
726
726
|
BROWSER_TIERS = ["standard", "premium"];
|
|
@@ -866,6 +866,10 @@ var init_browser = __esm({
|
|
|
866
866
|
get agentId() {
|
|
867
867
|
return this.recorder?.agentId ?? null;
|
|
868
868
|
}
|
|
869
|
+
/** `text` with this session's credentials (UI token, browser address) removed. */
|
|
870
|
+
scrub(text2) {
|
|
871
|
+
return this.scrubber.scrub(text2);
|
|
872
|
+
}
|
|
869
873
|
watchNetwork(page) {
|
|
870
874
|
page.on("request", () => {
|
|
871
875
|
this.inflight += 1;
|
|
@@ -1152,6 +1156,1269 @@ var init_browser = __esm({
|
|
|
1152
1156
|
}
|
|
1153
1157
|
});
|
|
1154
1158
|
|
|
1159
|
+
// src/worlds/nativeComputer/actions.ts
|
|
1160
|
+
function toNumber(value) {
|
|
1161
|
+
if (typeof value !== "number" || !Number.isFinite(value))
|
|
1162
|
+
throw new Error(`not a number: ${JSON.stringify(value) ?? String(value)}`);
|
|
1163
|
+
return value;
|
|
1164
|
+
}
|
|
1165
|
+
function toInt(value) {
|
|
1166
|
+
return Math.trunc(toNumber(value));
|
|
1167
|
+
}
|
|
1168
|
+
var ACTION_NAMES, SECRET_TEXT, BOUNDS, ComputerAction;
|
|
1169
|
+
var init_actions = __esm({
|
|
1170
|
+
"src/worlds/nativeComputer/actions.ts"() {
|
|
1171
|
+
"use strict";
|
|
1172
|
+
ACTION_NAMES = [
|
|
1173
|
+
"screenshot",
|
|
1174
|
+
"zoom",
|
|
1175
|
+
"click",
|
|
1176
|
+
"move",
|
|
1177
|
+
"mouse_down",
|
|
1178
|
+
"mouse_up",
|
|
1179
|
+
"drag",
|
|
1180
|
+
"scroll",
|
|
1181
|
+
"type",
|
|
1182
|
+
"key",
|
|
1183
|
+
"hold_key",
|
|
1184
|
+
"wait",
|
|
1185
|
+
"cursor_position",
|
|
1186
|
+
"history"
|
|
1187
|
+
];
|
|
1188
|
+
SECRET_TEXT = "[redacted]";
|
|
1189
|
+
BOUNDS = {
|
|
1190
|
+
seconds: [0, 300],
|
|
1191
|
+
repeat: [1, 100],
|
|
1192
|
+
count: [1, 3],
|
|
1193
|
+
dx: [-1e4, 1e4],
|
|
1194
|
+
dy: [-1e4, 1e4]
|
|
1195
|
+
};
|
|
1196
|
+
ComputerAction = class {
|
|
1197
|
+
constructor(name, args = {}) {
|
|
1198
|
+
this.name = name;
|
|
1199
|
+
this.args = args;
|
|
1200
|
+
if (!ACTION_NAMES.includes(name))
|
|
1201
|
+
throw new Error(`unknown computer action: ${name}`);
|
|
1202
|
+
for (const [key2, [low, high]] of Object.entries(BOUNDS)) {
|
|
1203
|
+
const value = args[key2];
|
|
1204
|
+
if (value !== void 0 && !(Number(value) >= low && Number(value) <= high))
|
|
1205
|
+
throw new Error(
|
|
1206
|
+
`${name} ${key2} must be between ${low} and ${high}, got ${String(value)}`
|
|
1207
|
+
);
|
|
1208
|
+
}
|
|
1209
|
+
}
|
|
1210
|
+
name;
|
|
1211
|
+
args;
|
|
1212
|
+
/** Flat arguments for the browser timeline and the trace: lists become
|
|
1213
|
+
* `"x,y"` strings, and typed text is withheld when it went into a
|
|
1214
|
+
* credential field. */
|
|
1215
|
+
recordArgs(secretText) {
|
|
1216
|
+
const out = {};
|
|
1217
|
+
for (const [key2, value] of Object.entries(this.args))
|
|
1218
|
+
out[key2] = Array.isArray(value) ? value.flat().join(",") : value;
|
|
1219
|
+
if (secretText && "text" in out) out.text = SECRET_TEXT;
|
|
1220
|
+
return out;
|
|
1221
|
+
}
|
|
1222
|
+
};
|
|
1223
|
+
}
|
|
1224
|
+
});
|
|
1225
|
+
|
|
1226
|
+
// src/worlds/nativeComputer/display.ts
|
|
1227
|
+
var FIT_STEP, Display;
|
|
1228
|
+
var init_display = __esm({
|
|
1229
|
+
"src/worlds/nativeComputer/display.ts"() {
|
|
1230
|
+
"use strict";
|
|
1231
|
+
FIT_STEP = 0.98;
|
|
1232
|
+
Display = class _Display {
|
|
1233
|
+
constructor(width, height, viewportWidth, viewportHeight) {
|
|
1234
|
+
this.width = width;
|
|
1235
|
+
this.height = height;
|
|
1236
|
+
this.viewportWidth = viewportWidth;
|
|
1237
|
+
this.viewportHeight = viewportHeight;
|
|
1238
|
+
}
|
|
1239
|
+
width;
|
|
1240
|
+
height;
|
|
1241
|
+
viewportWidth;
|
|
1242
|
+
viewportHeight;
|
|
1243
|
+
/** `size` when the caller names one; otherwise the largest downscale of the
|
|
1244
|
+
* viewport (at most 1:1) that `fits` the provider's limits. */
|
|
1245
|
+
static forViewport(viewport, size, fits = () => true) {
|
|
1246
|
+
const { width, height } = viewport;
|
|
1247
|
+
if (size) return _Display.sized(size[0], size[1], width, height);
|
|
1248
|
+
let scale = 1;
|
|
1249
|
+
while (!fits(Math.round(width * scale), Math.round(height * scale)))
|
|
1250
|
+
scale *= FIT_STEP;
|
|
1251
|
+
return new _Display(
|
|
1252
|
+
Math.round(width * scale),
|
|
1253
|
+
Math.round(height * scale),
|
|
1254
|
+
width,
|
|
1255
|
+
height
|
|
1256
|
+
);
|
|
1257
|
+
}
|
|
1258
|
+
/** A caller's display keeps the viewport's shape: screenshots are scaled
|
|
1259
|
+
* uniformly, so another aspect ratio would map clicks off the image. */
|
|
1260
|
+
static sized(width, height, viewportWidth, viewportHeight) {
|
|
1261
|
+
if (width <= 0 || height <= 0)
|
|
1262
|
+
throw new Error(`display ${width}x${height} must be positive`);
|
|
1263
|
+
const sameShape = width * viewportHeight / viewportWidth;
|
|
1264
|
+
if (Math.abs(sameShape - height) > 1)
|
|
1265
|
+
throw new Error(
|
|
1266
|
+
`display ${width}x${height} must keep the viewport's aspect ratio (${viewportWidth}x${viewportHeight}); try ${width}x${Math.round(sameShape)}`
|
|
1267
|
+
);
|
|
1268
|
+
return new _Display(width, height, viewportWidth, viewportHeight);
|
|
1269
|
+
}
|
|
1270
|
+
get scaled() {
|
|
1271
|
+
return this.width !== this.viewportWidth || this.height !== this.viewportHeight;
|
|
1272
|
+
}
|
|
1273
|
+
get scale() {
|
|
1274
|
+
return Math.min(
|
|
1275
|
+
this.width / this.viewportWidth,
|
|
1276
|
+
this.height / this.viewportHeight
|
|
1277
|
+
);
|
|
1278
|
+
}
|
|
1279
|
+
toPage(x, y) {
|
|
1280
|
+
return [
|
|
1281
|
+
x * this.viewportWidth / this.width,
|
|
1282
|
+
y * this.viewportHeight / this.height
|
|
1283
|
+
];
|
|
1284
|
+
}
|
|
1285
|
+
};
|
|
1286
|
+
}
|
|
1287
|
+
});
|
|
1288
|
+
|
|
1289
|
+
// src/worlds/nativeComputer/screen.ts
|
|
1290
|
+
function pngWidth(png) {
|
|
1291
|
+
if (png.length < 24 || !png.subarray(0, 8).equals(PNG_SIGNATURE)) return null;
|
|
1292
|
+
return png.readUInt32BE(16);
|
|
1293
|
+
}
|
|
1294
|
+
function isNativePage(page) {
|
|
1295
|
+
const candidate = page;
|
|
1296
|
+
const mouse = candidate?.mouse;
|
|
1297
|
+
return typeof candidate?.context === "function" && NATIVE_METHODS.every((m) => typeof mouse?.[m] === "function");
|
|
1298
|
+
}
|
|
1299
|
+
var FOCUSED_FIELD_JS, SECRET_FOCUS, DRAG_STEPS, PNG_SIGNATURE, NATIVE_METHODS, Screen;
|
|
1300
|
+
var init_screen = __esm({
|
|
1301
|
+
"src/worlds/nativeComputer/screen.ts"() {
|
|
1302
|
+
"use strict";
|
|
1303
|
+
init_browser();
|
|
1304
|
+
FOCUSED_FIELD_JS = "(() => { let e = document.activeElement; const inner = (el) => (el.shadowRoot && el.shadowRoot.activeElement) || (el.contentDocument && el.contentDocument.activeElement); while (e && inner(e)) e = inner(e); if (!e) return ''; if (e.tagName === 'IFRAME' || e.tagName === 'FRAME') return 'frame'; if (!(e.tagName === 'INPUT' || e.tagName === 'TEXTAREA' || e.isContentEditable)) return 'opaque'; return [e.type, e.name, e.id, e.getAttribute('autocomplete')].filter(Boolean).join(' '); })()";
|
|
1305
|
+
SECRET_FOCUS = ["password", "frame", "opaque"];
|
|
1306
|
+
DRAG_STEPS = 5;
|
|
1307
|
+
PNG_SIGNATURE = Buffer.from([
|
|
1308
|
+
137,
|
|
1309
|
+
80,
|
|
1310
|
+
78,
|
|
1311
|
+
71,
|
|
1312
|
+
13,
|
|
1313
|
+
10,
|
|
1314
|
+
26,
|
|
1315
|
+
10
|
|
1316
|
+
]);
|
|
1317
|
+
NATIVE_METHODS = ["move", "click", "down", "up", "wheel"];
|
|
1318
|
+
Screen = class {
|
|
1319
|
+
constructor(browser, display) {
|
|
1320
|
+
this.browser = browser;
|
|
1321
|
+
this.display = display;
|
|
1322
|
+
}
|
|
1323
|
+
browser;
|
|
1324
|
+
display;
|
|
1325
|
+
cursor = [0, 0];
|
|
1326
|
+
pixelRatio = 1;
|
|
1327
|
+
handlers = {
|
|
1328
|
+
screenshot: async () => ({ image: await this.screenshot() }),
|
|
1329
|
+
zoom: (a) => this.zoom(a),
|
|
1330
|
+
click: (a) => this.click(a),
|
|
1331
|
+
move: (a) => this.held(a.args.modifiers ?? [], () => this.moveTo(this.point(a))),
|
|
1332
|
+
mouse_down: async (a) => {
|
|
1333
|
+
await this.page.mouse.down({ button: a.args.button ?? "left" });
|
|
1334
|
+
return {};
|
|
1335
|
+
},
|
|
1336
|
+
mouse_up: async (a) => {
|
|
1337
|
+
await this.page.mouse.up({ button: a.args.button ?? "left" });
|
|
1338
|
+
return {};
|
|
1339
|
+
},
|
|
1340
|
+
drag: (a) => this.drag(a),
|
|
1341
|
+
scroll: (a) => this.scroll(a),
|
|
1342
|
+
type: async (a) => {
|
|
1343
|
+
await this.page.keyboard.type(a.args.text ?? "");
|
|
1344
|
+
return {};
|
|
1345
|
+
},
|
|
1346
|
+
key: (a) => this.key(a),
|
|
1347
|
+
hold_key: (a) => this.held(
|
|
1348
|
+
a.args.keys ?? [],
|
|
1349
|
+
() => this.page.waitForTimeout((a.args.seconds ?? 0) * 1e3)
|
|
1350
|
+
),
|
|
1351
|
+
wait: async (a) => {
|
|
1352
|
+
await this.page.waitForTimeout((a.args.seconds ?? 0) * 1e3);
|
|
1353
|
+
return {};
|
|
1354
|
+
},
|
|
1355
|
+
cursor_position: async () => ({
|
|
1356
|
+
text: `X=${this.cursor[0]}, Y=${this.cursor[1]}`
|
|
1357
|
+
}),
|
|
1358
|
+
history: async (a) => {
|
|
1359
|
+
const navigate = {
|
|
1360
|
+
back: () => this.page.goBack(),
|
|
1361
|
+
forward: () => this.page.goForward()
|
|
1362
|
+
};
|
|
1363
|
+
await navigate[a.args.direction ?? "back"]();
|
|
1364
|
+
return {};
|
|
1365
|
+
}
|
|
1366
|
+
};
|
|
1367
|
+
/** The live page (a new object after a reconnect), as pixel-level Playwright. */
|
|
1368
|
+
get page() {
|
|
1369
|
+
const page = this.browser.page;
|
|
1370
|
+
if (!isNativePage(page))
|
|
1371
|
+
throw new Error(
|
|
1372
|
+
"native computer use needs a Playwright page (mouse.move/click/down/up/wheel, context())"
|
|
1373
|
+
);
|
|
1374
|
+
return page;
|
|
1375
|
+
}
|
|
1376
|
+
run(action) {
|
|
1377
|
+
return this.handlers[action.name](action);
|
|
1378
|
+
}
|
|
1379
|
+
/** A PNG of the viewport at the model's display size. */
|
|
1380
|
+
async screenshot() {
|
|
1381
|
+
if (!this.display.scaled) return this.page.screenshot({ type: "png" });
|
|
1382
|
+
const { viewportWidth: width, viewportHeight: height } = this.display;
|
|
1383
|
+
return this.capture({ x: 0, y: 0, width, height }, this.display.scale);
|
|
1384
|
+
}
|
|
1385
|
+
/** Whether keystrokes go to a credential field (a password input, or one
|
|
1386
|
+
* named like a token, key or PIN), looking through shadow roots and
|
|
1387
|
+
* same-origin frames. An unreadable page, a cross-origin frame or a focus
|
|
1388
|
+
* that is not a text field (a closed shadow root's host) counts as one. */
|
|
1389
|
+
async focusedFieldIsSecret() {
|
|
1390
|
+
let described;
|
|
1391
|
+
try {
|
|
1392
|
+
described = String(await this.page.evaluate(FOCUSED_FIELD_JS) ?? "");
|
|
1393
|
+
} catch {
|
|
1394
|
+
return true;
|
|
1395
|
+
}
|
|
1396
|
+
return SECRET_FOCUS.some((prefix) => described.startsWith(prefix)) || SECRET_KEY.test(described);
|
|
1397
|
+
}
|
|
1398
|
+
/** CDP renders a clip at the page's device pixel ratio as well as its
|
|
1399
|
+
* `scale` (a Retina host doubles it), so a capture of the wrong width
|
|
1400
|
+
* measures that ratio and is taken once more, corrected. */
|
|
1401
|
+
async capture(clip, scale) {
|
|
1402
|
+
const wanted = Math.round(clip.width * scale);
|
|
1403
|
+
const png = await this.cdpCapture(clip, scale / this.pixelRatio);
|
|
1404
|
+
const width = pngWidth(png);
|
|
1405
|
+
if (width === null || Math.abs(width - wanted) <= 1) return png;
|
|
1406
|
+
this.pixelRatio *= width / wanted;
|
|
1407
|
+
return this.cdpCapture(clip, scale / this.pixelRatio);
|
|
1408
|
+
}
|
|
1409
|
+
async cdpCapture(clip, scale) {
|
|
1410
|
+
const page = this.page;
|
|
1411
|
+
const session = await page.context().newCDPSession(page);
|
|
1412
|
+
try {
|
|
1413
|
+
const shot = await session.send("Page.captureScreenshot", {
|
|
1414
|
+
format: "png",
|
|
1415
|
+
clip: { ...clip, scale }
|
|
1416
|
+
});
|
|
1417
|
+
return Buffer.from(shot.data, "base64");
|
|
1418
|
+
} finally {
|
|
1419
|
+
await session.detach();
|
|
1420
|
+
}
|
|
1421
|
+
}
|
|
1422
|
+
point(action) {
|
|
1423
|
+
const { x, y } = action.args;
|
|
1424
|
+
return x === void 0 || y === void 0 ? this.cursor : [x, y];
|
|
1425
|
+
}
|
|
1426
|
+
async moveTo(point2, steps = 1) {
|
|
1427
|
+
const [x, y] = this.display.toPage(point2[0], point2[1]);
|
|
1428
|
+
await this.page.mouse.move(x, y, { steps });
|
|
1429
|
+
this.cursor = point2;
|
|
1430
|
+
}
|
|
1431
|
+
async held(modifiers, fn) {
|
|
1432
|
+
for (const key2 of modifiers) await this.page.keyboard.down(key2);
|
|
1433
|
+
try {
|
|
1434
|
+
await fn();
|
|
1435
|
+
} finally {
|
|
1436
|
+
for (const key2 of [...modifiers].reverse())
|
|
1437
|
+
await this.page.keyboard.up(key2);
|
|
1438
|
+
}
|
|
1439
|
+
return {};
|
|
1440
|
+
}
|
|
1441
|
+
async zoom(action) {
|
|
1442
|
+
const [x0, y0, x1, y1] = action.args.region ?? [0, 0, 0, 0];
|
|
1443
|
+
const [left, top] = this.display.toPage(x0, y0);
|
|
1444
|
+
const [right, bottom] = this.display.toPage(x1, y1);
|
|
1445
|
+
if (right <= left || bottom <= top)
|
|
1446
|
+
throw new Error("zoom region must have x1 > x0 and y1 > y0");
|
|
1447
|
+
const width = right - left;
|
|
1448
|
+
const height = bottom - top;
|
|
1449
|
+
const scale = Math.min(
|
|
1450
|
+
this.display.width / width,
|
|
1451
|
+
this.display.height / height
|
|
1452
|
+
);
|
|
1453
|
+
return {
|
|
1454
|
+
image: await this.capture({ x: left, y: top, width, height }, scale)
|
|
1455
|
+
};
|
|
1456
|
+
}
|
|
1457
|
+
async click(action) {
|
|
1458
|
+
const point2 = this.point(action);
|
|
1459
|
+
return this.held(action.args.modifiers ?? [], async () => {
|
|
1460
|
+
await this.moveTo(point2);
|
|
1461
|
+
const [x, y] = this.display.toPage(point2[0], point2[1]);
|
|
1462
|
+
await this.page.mouse.click(x, y, {
|
|
1463
|
+
button: action.args.button ?? "left",
|
|
1464
|
+
clickCount: action.args.count ?? 1
|
|
1465
|
+
});
|
|
1466
|
+
});
|
|
1467
|
+
}
|
|
1468
|
+
async drag(action) {
|
|
1469
|
+
const path44 = action.args.path ?? [];
|
|
1470
|
+
if (path44.length < 2) throw new Error("a drag needs at least two points");
|
|
1471
|
+
return this.held(action.args.modifiers ?? [], async () => {
|
|
1472
|
+
await this.moveTo(path44[0]);
|
|
1473
|
+
await this.page.mouse.down({ button: "left" });
|
|
1474
|
+
try {
|
|
1475
|
+
for (const point2 of path44.slice(1)) await this.moveTo(point2, DRAG_STEPS);
|
|
1476
|
+
} finally {
|
|
1477
|
+
await this.page.mouse.up({ button: "left" });
|
|
1478
|
+
}
|
|
1479
|
+
});
|
|
1480
|
+
}
|
|
1481
|
+
async scroll(action) {
|
|
1482
|
+
await this.moveTo(this.point(action));
|
|
1483
|
+
const scale = this.display.scale;
|
|
1484
|
+
return this.held(
|
|
1485
|
+
action.args.modifiers ?? [],
|
|
1486
|
+
() => this.page.mouse.wheel(
|
|
1487
|
+
(action.args.dx ?? 0) / scale,
|
|
1488
|
+
(action.args.dy ?? 0) / scale
|
|
1489
|
+
)
|
|
1490
|
+
);
|
|
1491
|
+
}
|
|
1492
|
+
async key(action) {
|
|
1493
|
+
const combo = (action.args.keys ?? []).join("+");
|
|
1494
|
+
for (let i = 0; i < (action.args.repeat ?? 1); i += 1)
|
|
1495
|
+
await this.page.keyboard.press(combo);
|
|
1496
|
+
return {};
|
|
1497
|
+
}
|
|
1498
|
+
};
|
|
1499
|
+
}
|
|
1500
|
+
});
|
|
1501
|
+
|
|
1502
|
+
// src/tracing/media.ts
|
|
1503
|
+
async function putBytes(url, data, headers) {
|
|
1504
|
+
const controller = new AbortController();
|
|
1505
|
+
const timer = setTimeout(() => controller.abort(), PUT_TIMEOUT_MS);
|
|
1506
|
+
try {
|
|
1507
|
+
const res = await fetch(url, {
|
|
1508
|
+
method: "PUT",
|
|
1509
|
+
body: new Uint8Array(data),
|
|
1510
|
+
headers,
|
|
1511
|
+
signal: controller.signal
|
|
1512
|
+
});
|
|
1513
|
+
return {
|
|
1514
|
+
status: res.status,
|
|
1515
|
+
error: res.ok ? null : (await res.text()).slice(0, MAX_UPLOAD_ERROR)
|
|
1516
|
+
};
|
|
1517
|
+
} catch (error) {
|
|
1518
|
+
return {
|
|
1519
|
+
status: NETWORK_FAILURE_STATUS,
|
|
1520
|
+
error: error instanceof Error ? error.name : "Error"
|
|
1521
|
+
};
|
|
1522
|
+
} finally {
|
|
1523
|
+
clearTimeout(timer);
|
|
1524
|
+
}
|
|
1525
|
+
}
|
|
1526
|
+
var import_node_crypto, MEDIA_PATH, MAX_MEDIA_BYTES, PUT_TIMEOUT_MS, MAX_UPLOAD_ERROR, NETWORK_FAILURE_STATUS, MediaUploadError, MediaReference, MediaUploader;
|
|
1527
|
+
var init_media = __esm({
|
|
1528
|
+
"src/tracing/media.ts"() {
|
|
1529
|
+
"use strict";
|
|
1530
|
+
import_node_crypto = require("crypto");
|
|
1531
|
+
init_transport();
|
|
1532
|
+
MEDIA_PATH = "/api/public/media";
|
|
1533
|
+
MAX_MEDIA_BYTES = 5 * 1024 * 1024;
|
|
1534
|
+
PUT_TIMEOUT_MS = 3e4;
|
|
1535
|
+
MAX_UPLOAD_ERROR = 500;
|
|
1536
|
+
NETWORK_FAILURE_STATUS = 599;
|
|
1537
|
+
MediaUploadError = class extends Error {
|
|
1538
|
+
constructor(message, status) {
|
|
1539
|
+
super(message);
|
|
1540
|
+
this.status = status;
|
|
1541
|
+
this.name = "MediaUploadError";
|
|
1542
|
+
}
|
|
1543
|
+
status;
|
|
1544
|
+
};
|
|
1545
|
+
MediaReference = class {
|
|
1546
|
+
constructor(mediaId, contentType) {
|
|
1547
|
+
this.mediaId = mediaId;
|
|
1548
|
+
this.contentType = contentType;
|
|
1549
|
+
}
|
|
1550
|
+
mediaId;
|
|
1551
|
+
contentType;
|
|
1552
|
+
toString() {
|
|
1553
|
+
return `@@@langfuseMedia:type=${this.contentType}|id=${this.mediaId}|source=bytes@@@`;
|
|
1554
|
+
}
|
|
1555
|
+
};
|
|
1556
|
+
MediaUploader = class _MediaUploader {
|
|
1557
|
+
constructor(transport, put = putBytes, maxBytes = MAX_MEDIA_BYTES) {
|
|
1558
|
+
this.transport = transport;
|
|
1559
|
+
this.put = put;
|
|
1560
|
+
this.maxBytes = maxBytes;
|
|
1561
|
+
}
|
|
1562
|
+
transport;
|
|
1563
|
+
put;
|
|
1564
|
+
maxBytes;
|
|
1565
|
+
/** The uploader for `GATEWAY_HOST` / `GATEWAY_PUBLIC_KEY` /
|
|
1566
|
+
* `GATEWAY_SECRET_KEY` (the keys tracing exports with); null when any is unset. */
|
|
1567
|
+
static fromEnv(env = process.env) {
|
|
1568
|
+
const host = env.GATEWAY_HOST;
|
|
1569
|
+
const publicKey = env.GATEWAY_PUBLIC_KEY;
|
|
1570
|
+
const secretKey = env.GATEWAY_SECRET_KEY;
|
|
1571
|
+
if (!host || !publicKey || !secretKey) return null;
|
|
1572
|
+
return new _MediaUploader(
|
|
1573
|
+
new PlatformTransport({
|
|
1574
|
+
host: host.replace(/\/$/, ""),
|
|
1575
|
+
publicKey,
|
|
1576
|
+
secretKey
|
|
1577
|
+
})
|
|
1578
|
+
);
|
|
1579
|
+
}
|
|
1580
|
+
/** Store `data` linked to the trace (and observation) and return its reference. */
|
|
1581
|
+
async upload(data, link) {
|
|
1582
|
+
if (data.length > this.maxBytes)
|
|
1583
|
+
throw new MediaUploadError(
|
|
1584
|
+
`media is ${data.length} bytes, over the ${this.maxBytes}-byte cap`
|
|
1585
|
+
);
|
|
1586
|
+
const sha256Hash = (0, import_node_crypto.createHash)("sha256").update(data).digest("base64");
|
|
1587
|
+
const answer = await this.send("POST", MEDIA_PATH, {
|
|
1588
|
+
traceId: link.traceId,
|
|
1589
|
+
observationId: link.observationId,
|
|
1590
|
+
contentType: link.contentType,
|
|
1591
|
+
contentLength: data.length,
|
|
1592
|
+
sha256Hash,
|
|
1593
|
+
field: link.field
|
|
1594
|
+
});
|
|
1595
|
+
if (typeof answer.mediaId !== "string" || !answer.mediaId)
|
|
1596
|
+
throw new MediaUploadError(
|
|
1597
|
+
"POST /api/public/media answered without a mediaId"
|
|
1598
|
+
);
|
|
1599
|
+
const reference = new MediaReference(answer.mediaId, link.contentType);
|
|
1600
|
+
if (answer.uploadUrl)
|
|
1601
|
+
await this.store(reference, answer.uploadUrl, data, sha256Hash);
|
|
1602
|
+
return reference;
|
|
1603
|
+
}
|
|
1604
|
+
async store(reference, url, data, sha256Hash) {
|
|
1605
|
+
const started = Date.now();
|
|
1606
|
+
const { status, error } = await this.put(url, data, {
|
|
1607
|
+
"Content-Type": reference.contentType,
|
|
1608
|
+
"x-amz-checksum-sha256": sha256Hash,
|
|
1609
|
+
"x-ms-blob-type": "BlockBlob"
|
|
1610
|
+
});
|
|
1611
|
+
await this.send(
|
|
1612
|
+
"PATCH",
|
|
1613
|
+
`${MEDIA_PATH}/${encodeURIComponent(reference.mediaId)}`,
|
|
1614
|
+
{
|
|
1615
|
+
uploadedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1616
|
+
uploadHttpStatus: status,
|
|
1617
|
+
uploadHttpError: error,
|
|
1618
|
+
uploadTimeMs: Date.now() - started
|
|
1619
|
+
}
|
|
1620
|
+
);
|
|
1621
|
+
if (status < 200 || status >= 300)
|
|
1622
|
+
throw new MediaUploadError(
|
|
1623
|
+
`media storage refused the upload (HTTP ${status})`,
|
|
1624
|
+
status
|
|
1625
|
+
);
|
|
1626
|
+
}
|
|
1627
|
+
async send(method, route, body) {
|
|
1628
|
+
const reply = await this.transport.send(method, route, body);
|
|
1629
|
+
if (!reply.ok)
|
|
1630
|
+
throw new MediaUploadError(
|
|
1631
|
+
`${method} ${route} -> ${reply.status}`,
|
|
1632
|
+
reply.status
|
|
1633
|
+
);
|
|
1634
|
+
return reply.text ? JSON.parse(reply.text) : {};
|
|
1635
|
+
}
|
|
1636
|
+
};
|
|
1637
|
+
}
|
|
1638
|
+
});
|
|
1639
|
+
|
|
1640
|
+
// src/worlds/nativeComputer/trace.ts
|
|
1641
|
+
function loadOtelApi() {
|
|
1642
|
+
if (otelApi !== void 0) return otelApi;
|
|
1643
|
+
try {
|
|
1644
|
+
otelApi = require("@opentelemetry/api");
|
|
1645
|
+
} catch {
|
|
1646
|
+
otelApi = null;
|
|
1647
|
+
}
|
|
1648
|
+
return otelApi;
|
|
1649
|
+
}
|
|
1650
|
+
function errorText(error) {
|
|
1651
|
+
return error instanceof Error ? `${error.name}: ${error.message}` : String(error);
|
|
1652
|
+
}
|
|
1653
|
+
function errorName(error) {
|
|
1654
|
+
return error instanceof Error ? error.name : "Error";
|
|
1655
|
+
}
|
|
1656
|
+
var SPAN_PREFIX, MAX_UPLOAD_FAILURES, TRACER_NAME, MAX_ERROR, otelApi, ActionTracer;
|
|
1657
|
+
var init_trace = __esm({
|
|
1658
|
+
"src/worlds/nativeComputer/trace.ts"() {
|
|
1659
|
+
"use strict";
|
|
1660
|
+
init_media();
|
|
1661
|
+
SPAN_PREFIX = "computer.";
|
|
1662
|
+
MAX_UPLOAD_FAILURES = 3;
|
|
1663
|
+
TRACER_NAME = "@withgateway/sdk";
|
|
1664
|
+
MAX_ERROR = 1e3;
|
|
1665
|
+
ActionTracer = class _ActionTracer {
|
|
1666
|
+
constructor(media, warn2 = (m) => console.warn(m)) {
|
|
1667
|
+
this.media = media;
|
|
1668
|
+
this.warn = warn2;
|
|
1669
|
+
}
|
|
1670
|
+
media;
|
|
1671
|
+
warn;
|
|
1672
|
+
failures = 0;
|
|
1673
|
+
warned = false;
|
|
1674
|
+
static fromEnv() {
|
|
1675
|
+
return new _ActionTracer(MediaUploader.fromEnv());
|
|
1676
|
+
}
|
|
1677
|
+
/** `args` are already redacted. A failure's status goes through `scrub`:
|
|
1678
|
+
* browser errors quote the session's ws URL and UI token. */
|
|
1679
|
+
async span(action, args, run, capture, scrub) {
|
|
1680
|
+
const otel = loadOtelApi();
|
|
1681
|
+
if (!otel) return run();
|
|
1682
|
+
const { SpanStatusCode, trace: trace3 } = otel;
|
|
1683
|
+
const attributes = {
|
|
1684
|
+
"gateway.observation.type": "tool",
|
|
1685
|
+
"tool.name": SPAN_PREFIX + action.name,
|
|
1686
|
+
"gateway.observation.input": JSON.stringify({
|
|
1687
|
+
action: action.name,
|
|
1688
|
+
...args
|
|
1689
|
+
})
|
|
1690
|
+
};
|
|
1691
|
+
return trace3.getTracer(TRACER_NAME).startActiveSpan(
|
|
1692
|
+
SPAN_PREFIX + action.name,
|
|
1693
|
+
{ attributes },
|
|
1694
|
+
async (span) => {
|
|
1695
|
+
try {
|
|
1696
|
+
const result = await run();
|
|
1697
|
+
await this.finish(span, result, capture);
|
|
1698
|
+
span.setStatus({ code: SpanStatusCode.OK });
|
|
1699
|
+
return result;
|
|
1700
|
+
} catch (error) {
|
|
1701
|
+
span.setStatus({
|
|
1702
|
+
code: SpanStatusCode.ERROR,
|
|
1703
|
+
message: scrub(errorText(error)).slice(0, MAX_ERROR)
|
|
1704
|
+
});
|
|
1705
|
+
throw error;
|
|
1706
|
+
} finally {
|
|
1707
|
+
span.end();
|
|
1708
|
+
}
|
|
1709
|
+
}
|
|
1710
|
+
);
|
|
1711
|
+
}
|
|
1712
|
+
async finish(span, result, capture) {
|
|
1713
|
+
if (!span.isRecording()) return;
|
|
1714
|
+
const output = {
|
|
1715
|
+
screenshot: await this.screenshot(span, result, capture)
|
|
1716
|
+
};
|
|
1717
|
+
if (result.text !== void 0) output.text = result.text;
|
|
1718
|
+
span.setAttribute("gateway.observation.output", JSON.stringify(output));
|
|
1719
|
+
}
|
|
1720
|
+
async screenshot(span, result, capture) {
|
|
1721
|
+
let png;
|
|
1722
|
+
try {
|
|
1723
|
+
png = result.image ?? await capture();
|
|
1724
|
+
} catch (error) {
|
|
1725
|
+
return `[screenshot unavailable: ${errorName(error)}]`;
|
|
1726
|
+
}
|
|
1727
|
+
return this.reference(png, span);
|
|
1728
|
+
}
|
|
1729
|
+
async reference(png, span) {
|
|
1730
|
+
if (!this.media)
|
|
1731
|
+
return "[screenshot not uploaded: GATEWAY_HOST / GATEWAY_PUBLIC_KEY / GATEWAY_SECRET_KEY unset]";
|
|
1732
|
+
if (this.failures >= MAX_UPLOAD_FAILURES)
|
|
1733
|
+
return "[screenshot not uploaded: uploads disabled after repeated failures]";
|
|
1734
|
+
const { traceId, spanId } = span.spanContext();
|
|
1735
|
+
try {
|
|
1736
|
+
const reference = await this.media.upload(png, {
|
|
1737
|
+
contentType: "image/png",
|
|
1738
|
+
traceId,
|
|
1739
|
+
observationId: spanId,
|
|
1740
|
+
field: "output"
|
|
1741
|
+
});
|
|
1742
|
+
this.failures = 0;
|
|
1743
|
+
return reference.toString();
|
|
1744
|
+
} catch (error) {
|
|
1745
|
+
return this.failed(error);
|
|
1746
|
+
}
|
|
1747
|
+
}
|
|
1748
|
+
failed(error) {
|
|
1749
|
+
this.failures += 1;
|
|
1750
|
+
if (!this.warned) {
|
|
1751
|
+
this.warned = true;
|
|
1752
|
+
this.warn(
|
|
1753
|
+
`native computer: screenshot upload failed (${errorName(error)}: ${error instanceof Error ? error.message : String(error)}); spans keep going without it`
|
|
1754
|
+
);
|
|
1755
|
+
}
|
|
1756
|
+
return `[screenshot not uploaded: ${errorName(error)}]`;
|
|
1757
|
+
}
|
|
1758
|
+
};
|
|
1759
|
+
}
|
|
1760
|
+
});
|
|
1761
|
+
|
|
1762
|
+
// src/worlds/nativeComputer/base.ts
|
|
1763
|
+
function readField(item, ...names) {
|
|
1764
|
+
const record = item ?? {};
|
|
1765
|
+
return names.map((name) => record[name]).find((value) => value !== void 0 && value !== null);
|
|
1766
|
+
}
|
|
1767
|
+
var REPLAYABLE, SETTLING, EVENT_PREFIX, NativeComputer;
|
|
1768
|
+
var init_base = __esm({
|
|
1769
|
+
"src/worlds/nativeComputer/base.ts"() {
|
|
1770
|
+
"use strict";
|
|
1771
|
+
init_browser();
|
|
1772
|
+
init_actions();
|
|
1773
|
+
init_display();
|
|
1774
|
+
init_screen();
|
|
1775
|
+
init_trace();
|
|
1776
|
+
REPLAYABLE = /* @__PURE__ */ new Set(["screenshot", "zoom", "cursor_position", "wait"]);
|
|
1777
|
+
SETTLING = /* @__PURE__ */ new Set(["click", "mouse_up", "drag", "key", "history"]);
|
|
1778
|
+
EVENT_PREFIX = "computer_";
|
|
1779
|
+
NativeComputer = class _NativeComputer {
|
|
1780
|
+
constructor(browser, options = {}) {
|
|
1781
|
+
this.browser = browser;
|
|
1782
|
+
const kind = this.constructor;
|
|
1783
|
+
this.display = Display.forViewport(
|
|
1784
|
+
browser.viewport,
|
|
1785
|
+
options.display,
|
|
1786
|
+
(w, h) => kind.fits(w, h)
|
|
1787
|
+
);
|
|
1788
|
+
this.screen = new Screen(browser, this.display);
|
|
1789
|
+
this.tracer = options.tracer ?? ActionTracer.fromEnv();
|
|
1790
|
+
}
|
|
1791
|
+
browser;
|
|
1792
|
+
static kinds = /* @__PURE__ */ new Map();
|
|
1793
|
+
display;
|
|
1794
|
+
screen;
|
|
1795
|
+
tracer;
|
|
1796
|
+
queue = Promise.resolve();
|
|
1797
|
+
static register(provider, kind) {
|
|
1798
|
+
_NativeComputer.kinds.set(provider, kind);
|
|
1799
|
+
}
|
|
1800
|
+
static get providers() {
|
|
1801
|
+
return [..._NativeComputer.kinds.keys()].sort();
|
|
1802
|
+
}
|
|
1803
|
+
static forProvider(provider, browser, options = {}) {
|
|
1804
|
+
const Kind = _NativeComputer.kinds.get(provider);
|
|
1805
|
+
if (!Kind)
|
|
1806
|
+
throw new Error(
|
|
1807
|
+
`unknown computer-use provider '${provider}'; choose from ${_NativeComputer.providers.join(", ")}`
|
|
1808
|
+
);
|
|
1809
|
+
return new Kind(browser, options);
|
|
1810
|
+
}
|
|
1811
|
+
/** Whether a screenshot of this size is within the provider's limits. */
|
|
1812
|
+
static fits(_width, _height) {
|
|
1813
|
+
return true;
|
|
1814
|
+
}
|
|
1815
|
+
/** Run one provider-shaped action (an OpenAI action object, or an Anthropic
|
|
1816
|
+
* `{ action: "left_click", ... }` input) and return what it produced: the
|
|
1817
|
+
* door for any agent framework that hands actions over one at a time. */
|
|
1818
|
+
executeAction(raw) {
|
|
1819
|
+
return this.perform(this.parse(raw));
|
|
1820
|
+
}
|
|
1821
|
+
/** Run one action on the page: reported on the session's browser timeline
|
|
1822
|
+
* and, when tracing is on, as a span with the screen after. */
|
|
1823
|
+
async perform(action) {
|
|
1824
|
+
const secret = action.name === "type" && await this.screen.focusedFieldIsSecret();
|
|
1825
|
+
const event = EVENT_PREFIX + action.name;
|
|
1826
|
+
const args = redactActionArgs(event, action.recordArgs(secret));
|
|
1827
|
+
return this.tracer.span(
|
|
1828
|
+
action,
|
|
1829
|
+
args,
|
|
1830
|
+
() => this.browser.act(
|
|
1831
|
+
event,
|
|
1832
|
+
args,
|
|
1833
|
+
() => this.runOnScreen(action),
|
|
1834
|
+
this.onLoss(action)
|
|
1835
|
+
),
|
|
1836
|
+
() => this.screen.screenshot(),
|
|
1837
|
+
(text2) => this.browser.scrub(text2)
|
|
1838
|
+
);
|
|
1839
|
+
}
|
|
1840
|
+
async performAll(actions) {
|
|
1841
|
+
const results = [];
|
|
1842
|
+
for (const action of actions) results.push(await this.perform(action));
|
|
1843
|
+
return results;
|
|
1844
|
+
}
|
|
1845
|
+
/** The screen as the model sees it, as a traced `screenshot` action. */
|
|
1846
|
+
async screenshot() {
|
|
1847
|
+
return (await this.perform(new ComputerAction("screenshot"))).image ?? Buffer.alloc(0);
|
|
1848
|
+
}
|
|
1849
|
+
/** Run `fn` after every earlier call made through here: the AI SDK starts a
|
|
1850
|
+
* step's tool calls concurrently, but one screen takes one action at a time. */
|
|
1851
|
+
serial(fn) {
|
|
1852
|
+
const next = this.queue.then(fn, fn);
|
|
1853
|
+
this.queue = next.catch(() => void 0);
|
|
1854
|
+
return next;
|
|
1855
|
+
}
|
|
1856
|
+
async runOnScreen(action) {
|
|
1857
|
+
const result = await this.screen.run(action);
|
|
1858
|
+
if (SETTLING.has(action.name)) await this.browser.settle();
|
|
1859
|
+
return result;
|
|
1860
|
+
}
|
|
1861
|
+
onLoss(action) {
|
|
1862
|
+
return REPLAYABLE.has(action.name) ? "retry" : "report";
|
|
1863
|
+
}
|
|
1864
|
+
};
|
|
1865
|
+
}
|
|
1866
|
+
});
|
|
1867
|
+
|
|
1868
|
+
// src/worlds/nativeComputer/keys.ts
|
|
1869
|
+
function playwrightKey(token) {
|
|
1870
|
+
return KEY_NAMES[token.toLowerCase()] ?? token;
|
|
1871
|
+
}
|
|
1872
|
+
function letterOrName(key2) {
|
|
1873
|
+
return /^[a-zA-Z]$/.test(key2) ? key2.toLowerCase() : playwrightKey(key2);
|
|
1874
|
+
}
|
|
1875
|
+
function modifierChord(text2) {
|
|
1876
|
+
return typeof text2 === "string" && text2 ? [...KeyChord.fromXdotool(text2).keys] : [];
|
|
1877
|
+
}
|
|
1878
|
+
function modifierKeys(keys) {
|
|
1879
|
+
return Array.isArray(keys) && keys.length > 0 ? [...KeyChord.fromKeys(keys.map(String)).keys] : [];
|
|
1880
|
+
}
|
|
1881
|
+
var F_KEYS, KEY_NAMES, KeyChord;
|
|
1882
|
+
var init_keys = __esm({
|
|
1883
|
+
"src/worlds/nativeComputer/keys.ts"() {
|
|
1884
|
+
"use strict";
|
|
1885
|
+
F_KEYS = Object.fromEntries(
|
|
1886
|
+
Array.from({ length: 12 }, (_, i) => [`f${i + 1}`, `F${i + 1}`])
|
|
1887
|
+
);
|
|
1888
|
+
KEY_NAMES = {
|
|
1889
|
+
return: "Enter",
|
|
1890
|
+
enter: "Enter",
|
|
1891
|
+
kp_enter: "Enter",
|
|
1892
|
+
esc: "Escape",
|
|
1893
|
+
escape: "Escape",
|
|
1894
|
+
tab: "Tab",
|
|
1895
|
+
space: "Space",
|
|
1896
|
+
backspace: "Backspace",
|
|
1897
|
+
delete: "Delete",
|
|
1898
|
+
del: "Delete",
|
|
1899
|
+
insert: "Insert",
|
|
1900
|
+
home: "Home",
|
|
1901
|
+
end: "End",
|
|
1902
|
+
pageup: "PageUp",
|
|
1903
|
+
page_up: "PageUp",
|
|
1904
|
+
prior: "PageUp",
|
|
1905
|
+
pagedown: "PageDown",
|
|
1906
|
+
page_down: "PageDown",
|
|
1907
|
+
next: "PageDown",
|
|
1908
|
+
up: "ArrowUp",
|
|
1909
|
+
arrowup: "ArrowUp",
|
|
1910
|
+
down: "ArrowDown",
|
|
1911
|
+
arrowdown: "ArrowDown",
|
|
1912
|
+
left: "ArrowLeft",
|
|
1913
|
+
arrowleft: "ArrowLeft",
|
|
1914
|
+
right: "ArrowRight",
|
|
1915
|
+
arrowright: "ArrowRight",
|
|
1916
|
+
ctrl: "Control",
|
|
1917
|
+
control: "Control",
|
|
1918
|
+
shift: "Shift",
|
|
1919
|
+
alt: "Alt",
|
|
1920
|
+
option: "Alt",
|
|
1921
|
+
super: "Meta",
|
|
1922
|
+
meta: "Meta",
|
|
1923
|
+
cmd: "Meta",
|
|
1924
|
+
command: "Meta",
|
|
1925
|
+
win: "Meta",
|
|
1926
|
+
capslock: "CapsLock",
|
|
1927
|
+
caps_lock: "CapsLock",
|
|
1928
|
+
plus: "+",
|
|
1929
|
+
minus: "-",
|
|
1930
|
+
...F_KEYS
|
|
1931
|
+
};
|
|
1932
|
+
KeyChord = class _KeyChord {
|
|
1933
|
+
constructor(keys) {
|
|
1934
|
+
this.keys = keys;
|
|
1935
|
+
if (keys.length === 0)
|
|
1936
|
+
throw new Error("a key action needs at least one key");
|
|
1937
|
+
}
|
|
1938
|
+
keys;
|
|
1939
|
+
/** `ctrl+shift+t` / `Return`: Anthropic's vocabulary, case kept. */
|
|
1940
|
+
static fromXdotool(text2) {
|
|
1941
|
+
return new _KeyChord(
|
|
1942
|
+
text2.trim().split("+").filter(Boolean).map(playwrightKey)
|
|
1943
|
+
);
|
|
1944
|
+
}
|
|
1945
|
+
/** `["CTRL", "A"]`: OpenAI's vocabulary. A lone letter is the unshifted key. */
|
|
1946
|
+
static fromKeys(keys) {
|
|
1947
|
+
return new _KeyChord(keys.map(letterOrName));
|
|
1948
|
+
}
|
|
1949
|
+
/** What `page.keyboard.press` takes: `Control+a`. */
|
|
1950
|
+
get combo() {
|
|
1951
|
+
return this.keys.join("+");
|
|
1952
|
+
}
|
|
1953
|
+
};
|
|
1954
|
+
}
|
|
1955
|
+
});
|
|
1956
|
+
|
|
1957
|
+
// src/worlds/nativeComputer/anthropic.ts
|
|
1958
|
+
function required(raw, key2) {
|
|
1959
|
+
const value = raw[key2];
|
|
1960
|
+
if (value === void 0 || value === null)
|
|
1961
|
+
throw new Error(`${String(raw.action)} needs ${key2}`);
|
|
1962
|
+
return value;
|
|
1963
|
+
}
|
|
1964
|
+
function pair(raw, key2) {
|
|
1965
|
+
const value = required(raw, key2);
|
|
1966
|
+
return [toInt(value[0]), toInt(value[1])];
|
|
1967
|
+
}
|
|
1968
|
+
function point(raw) {
|
|
1969
|
+
if (raw.coordinate === void 0 || raw.coordinate === null) return {};
|
|
1970
|
+
const [x, y] = pair(raw, "coordinate");
|
|
1971
|
+
return { x, y };
|
|
1972
|
+
}
|
|
1973
|
+
function chord(raw) {
|
|
1974
|
+
return [...KeyChord.fromXdotool(String(required(raw, "text"))).keys];
|
|
1975
|
+
}
|
|
1976
|
+
function click(button, count) {
|
|
1977
|
+
return (raw) => new ComputerAction("click", {
|
|
1978
|
+
...point(raw),
|
|
1979
|
+
button,
|
|
1980
|
+
count,
|
|
1981
|
+
modifiers: modifierChord(raw.text)
|
|
1982
|
+
});
|
|
1983
|
+
}
|
|
1984
|
+
var SCROLL_STEP_PX, NOT_EXECUTED, MAX_ERROR2, SCROLL_DIRECTIONS, MEMBERS, AnthropicComputer, AnthropicComputer20251124;
|
|
1985
|
+
var init_anthropic = __esm({
|
|
1986
|
+
"src/worlds/nativeComputer/anthropic.ts"() {
|
|
1987
|
+
"use strict";
|
|
1988
|
+
init_actions();
|
|
1989
|
+
init_base();
|
|
1990
|
+
init_keys();
|
|
1991
|
+
SCROLL_STEP_PX = 100;
|
|
1992
|
+
NOT_EXECUTED = "Not executed: an earlier computer action in this turn failed.";
|
|
1993
|
+
MAX_ERROR2 = 1e3;
|
|
1994
|
+
SCROLL_DIRECTIONS = {
|
|
1995
|
+
up: [0, -1],
|
|
1996
|
+
down: [0, 1],
|
|
1997
|
+
left: [-1, 0],
|
|
1998
|
+
right: [1, 0]
|
|
1999
|
+
};
|
|
2000
|
+
MEMBERS = {
|
|
2001
|
+
screenshot: () => new ComputerAction("screenshot"),
|
|
2002
|
+
zoom: (raw) => new ComputerAction("zoom", {
|
|
2003
|
+
region: required(raw, "region").map(toInt)
|
|
2004
|
+
}),
|
|
2005
|
+
left_click: click("left", 1),
|
|
2006
|
+
right_click: click("right", 1),
|
|
2007
|
+
middle_click: click("middle", 1),
|
|
2008
|
+
double_click: click("left", 2),
|
|
2009
|
+
triple_click: click("left", 3),
|
|
2010
|
+
left_click_drag: (raw) => new ComputerAction("drag", {
|
|
2011
|
+
path: [pair(raw, "start_coordinate"), pair(raw, "coordinate")],
|
|
2012
|
+
modifiers: modifierChord(raw.text)
|
|
2013
|
+
}),
|
|
2014
|
+
mouse_move: (raw) => {
|
|
2015
|
+
const [x, y] = pair(raw, "coordinate");
|
|
2016
|
+
return new ComputerAction("move", { x, y });
|
|
2017
|
+
},
|
|
2018
|
+
left_mouse_down: () => new ComputerAction("mouse_down", { button: "left" }),
|
|
2019
|
+
left_mouse_up: () => new ComputerAction("mouse_up", { button: "left" }),
|
|
2020
|
+
cursor_position: () => new ComputerAction("cursor_position"),
|
|
2021
|
+
scroll: (raw) => {
|
|
2022
|
+
const direction = String(raw.scroll_direction ?? "down");
|
|
2023
|
+
if (!Object.hasOwn(SCROLL_DIRECTIONS, direction))
|
|
2024
|
+
throw new Error(
|
|
2025
|
+
`scroll_direction must be one of ${Object.keys(SCROLL_DIRECTIONS).join(", ")}`
|
|
2026
|
+
);
|
|
2027
|
+
const [dx, dy] = SCROLL_DIRECTIONS[direction];
|
|
2028
|
+
const amount = toInt(raw.scroll_amount ?? 1) * SCROLL_STEP_PX;
|
|
2029
|
+
return new ComputerAction("scroll", {
|
|
2030
|
+
...point(raw),
|
|
2031
|
+
dx: dx * amount,
|
|
2032
|
+
dy: dy * amount,
|
|
2033
|
+
modifiers: modifierChord(raw.text)
|
|
2034
|
+
});
|
|
2035
|
+
},
|
|
2036
|
+
type: (raw) => new ComputerAction("type", { text: String(required(raw, "text")) }),
|
|
2037
|
+
key: (raw) => new ComputerAction("key", {
|
|
2038
|
+
keys: chord(raw),
|
|
2039
|
+
repeat: toInt(raw.repeat ?? 1)
|
|
2040
|
+
}),
|
|
2041
|
+
hold_key: (raw) => new ComputerAction("hold_key", {
|
|
2042
|
+
keys: chord(raw),
|
|
2043
|
+
seconds: toNumber(required(raw, "duration"))
|
|
2044
|
+
}),
|
|
2045
|
+
wait: (raw) => new ComputerAction("wait", { seconds: toNumber(raw.duration ?? 1) })
|
|
2046
|
+
};
|
|
2047
|
+
AnthropicComputer = class _AnthropicComputer extends NativeComputer {
|
|
2048
|
+
static TOOL_TYPE = "computer_toolset_20260801";
|
|
2049
|
+
static TOOLSET = "computer";
|
|
2050
|
+
static BETA = null;
|
|
2051
|
+
static MAX_LONG_EDGE = 2576;
|
|
2052
|
+
static MAX_VISUAL_TOKENS = 4784;
|
|
2053
|
+
static PATCH_PX = 28;
|
|
2054
|
+
static fits(width, height) {
|
|
2055
|
+
const tokens = Math.ceil(width / this.PATCH_PX) * Math.ceil(height / this.PATCH_PX);
|
|
2056
|
+
return Math.max(width, height) <= this.MAX_LONG_EDGE && tokens <= this.MAX_VISUAL_TOKENS;
|
|
2057
|
+
}
|
|
2058
|
+
tool() {
|
|
2059
|
+
return { type: _AnthropicComputer.TOOL_TYPE };
|
|
2060
|
+
}
|
|
2061
|
+
/** Whether a content block is a call to this computer. */
|
|
2062
|
+
owns(block) {
|
|
2063
|
+
return readField(block, "type") === "tool_use" && readField(block, "toolset_name") === _AnthropicComputer.TOOLSET;
|
|
2064
|
+
}
|
|
2065
|
+
member(block) {
|
|
2066
|
+
return [
|
|
2067
|
+
String(readField(block, "name")),
|
|
2068
|
+
{ ...readField(block, "input") ?? {} }
|
|
2069
|
+
];
|
|
2070
|
+
}
|
|
2071
|
+
parse(raw) {
|
|
2072
|
+
const name = String(readField(raw, "action"));
|
|
2073
|
+
const parser = Object.hasOwn(MEMBERS, name) ? MEMBERS[name] : void 0;
|
|
2074
|
+
if (!parser) throw new Error(`unknown computer action: ${name}`);
|
|
2075
|
+
return parser(raw);
|
|
2076
|
+
}
|
|
2077
|
+
/** Run every computer `tool_use` in a response's content, in order, and
|
|
2078
|
+
* return one `tool_result` per block. Other blocks are skipped. */
|
|
2079
|
+
async execute(content) {
|
|
2080
|
+
const results = [];
|
|
2081
|
+
let failed2 = false;
|
|
2082
|
+
for (const block of content) {
|
|
2083
|
+
if (!this.owns(block)) continue;
|
|
2084
|
+
if (failed2) {
|
|
2085
|
+
results.push(this.envelope(block, NOT_EXECUTED, true));
|
|
2086
|
+
continue;
|
|
2087
|
+
}
|
|
2088
|
+
const [result, blockFailed] = await this.runBlock(block);
|
|
2089
|
+
results.push(result);
|
|
2090
|
+
failed2 = blockFailed;
|
|
2091
|
+
}
|
|
2092
|
+
return results;
|
|
2093
|
+
}
|
|
2094
|
+
/** The content an `ActionResult` goes back to the model as. */
|
|
2095
|
+
static content(result) {
|
|
2096
|
+
if (result.image)
|
|
2097
|
+
return [
|
|
2098
|
+
{
|
|
2099
|
+
type: "image",
|
|
2100
|
+
source: {
|
|
2101
|
+
type: "base64",
|
|
2102
|
+
media_type: "image/png",
|
|
2103
|
+
data: result.image.toString("base64")
|
|
2104
|
+
}
|
|
2105
|
+
}
|
|
2106
|
+
];
|
|
2107
|
+
return [{ type: "text", text: result.text ?? "OK" }];
|
|
2108
|
+
}
|
|
2109
|
+
/** For `anthropic.tools.computerToolset_20260801({ ...computer.aiSdk() })`
|
|
2110
|
+
* (or `computer_20251124` with the legacy kind): `execute` runs one action
|
|
2111
|
+
* and returns `{ type: "image", data }` or text; `toModelOutput` turns that
|
|
2112
|
+
* into the tool result. Calls run one at a time, and once a call fails the
|
|
2113
|
+
* rest of that step's calls answer as not executed. */
|
|
2114
|
+
aiSdk() {
|
|
2115
|
+
let failedStep;
|
|
2116
|
+
const execute = (input, options) => this.serial(async () => {
|
|
2117
|
+
const step = options?.messages?.length;
|
|
2118
|
+
if (step !== void 0 && step === failedStep)
|
|
2119
|
+
throw new Error(NOT_EXECUTED);
|
|
2120
|
+
try {
|
|
2121
|
+
return _AnthropicComputer.aiSdkOutput(await this.executeAction(input));
|
|
2122
|
+
} catch (error) {
|
|
2123
|
+
failedStep = step;
|
|
2124
|
+
throw error instanceof Error ? new Error(this.browser.scrub(error.message)) : error;
|
|
2125
|
+
}
|
|
2126
|
+
});
|
|
2127
|
+
return {
|
|
2128
|
+
execute,
|
|
2129
|
+
toModelOutput: ({ output }) => _AnthropicComputer.aiSdkModelOutput(output)
|
|
2130
|
+
};
|
|
2131
|
+
}
|
|
2132
|
+
static aiSdkOutput(result) {
|
|
2133
|
+
if (result.image)
|
|
2134
|
+
return { type: "image", data: result.image.toString("base64") };
|
|
2135
|
+
return result.text ?? "OK";
|
|
2136
|
+
}
|
|
2137
|
+
/** `image-data` is what AI SDK 6's Anthropic provider turns into an image
|
|
2138
|
+
* block; AI SDK 7 still accepts it (and converts it to a `file` part). */
|
|
2139
|
+
static aiSdkModelOutput(output) {
|
|
2140
|
+
if (typeof output === "string") return { type: "text", value: output };
|
|
2141
|
+
return {
|
|
2142
|
+
type: "content",
|
|
2143
|
+
value: [
|
|
2144
|
+
{ type: "image-data", data: output.data, mediaType: "image/png" }
|
|
2145
|
+
]
|
|
2146
|
+
};
|
|
2147
|
+
}
|
|
2148
|
+
envelope(block, content, isError = false) {
|
|
2149
|
+
return {
|
|
2150
|
+
type: "tool_result",
|
|
2151
|
+
tool_use_id: String(readField(block, "id")),
|
|
2152
|
+
toolset_name: _AnthropicComputer.TOOLSET,
|
|
2153
|
+
content,
|
|
2154
|
+
...isError ? { is_error: true } : {}
|
|
2155
|
+
};
|
|
2156
|
+
}
|
|
2157
|
+
async runBlock(block) {
|
|
2158
|
+
const [name, payload] = this.member(block);
|
|
2159
|
+
try {
|
|
2160
|
+
const result = await this.executeAction({ ...payload, action: name });
|
|
2161
|
+
return [this.envelope(block, _AnthropicComputer.content(result)), false];
|
|
2162
|
+
} catch (error) {
|
|
2163
|
+
const detail = error instanceof Error ? `${error.name}: ${error.message}` : String(error);
|
|
2164
|
+
return [
|
|
2165
|
+
this.envelope(
|
|
2166
|
+
block,
|
|
2167
|
+
this.browser.scrub(`Error: ${detail}`).slice(0, MAX_ERROR2),
|
|
2168
|
+
true
|
|
2169
|
+
),
|
|
2170
|
+
true
|
|
2171
|
+
];
|
|
2172
|
+
}
|
|
2173
|
+
}
|
|
2174
|
+
};
|
|
2175
|
+
AnthropicComputer20251124 = class _AnthropicComputer20251124 extends AnthropicComputer {
|
|
2176
|
+
static TOOL_TYPE = "computer_20251124";
|
|
2177
|
+
static BETA = "computer-use-2025-11-24";
|
|
2178
|
+
static MAX_LONG_EDGE = 1568;
|
|
2179
|
+
static MAX_PIXELS = 115e4;
|
|
2180
|
+
static fits(width, height) {
|
|
2181
|
+
return Math.max(width, height) <= this.MAX_LONG_EDGE && width * height <= this.MAX_PIXELS;
|
|
2182
|
+
}
|
|
2183
|
+
tool() {
|
|
2184
|
+
return {
|
|
2185
|
+
type: _AnthropicComputer20251124.TOOL_TYPE,
|
|
2186
|
+
name: AnthropicComputer.TOOLSET,
|
|
2187
|
+
display_width_px: this.display.width,
|
|
2188
|
+
display_height_px: this.display.height,
|
|
2189
|
+
enable_zoom: true
|
|
2190
|
+
};
|
|
2191
|
+
}
|
|
2192
|
+
owns(block) {
|
|
2193
|
+
return readField(block, "type") === "tool_use" && readField(block, "name") === AnthropicComputer.TOOLSET;
|
|
2194
|
+
}
|
|
2195
|
+
member(block) {
|
|
2196
|
+
const { action, ...payload } = readField(block, "input") ?? {};
|
|
2197
|
+
return [String(action ?? ""), payload];
|
|
2198
|
+
}
|
|
2199
|
+
envelope(block, content, isError = false) {
|
|
2200
|
+
const { toolset_name: _dropped, ...rest } = super.envelope(
|
|
2201
|
+
block,
|
|
2202
|
+
content,
|
|
2203
|
+
isError
|
|
2204
|
+
);
|
|
2205
|
+
return rest;
|
|
2206
|
+
}
|
|
2207
|
+
};
|
|
2208
|
+
NativeComputer.register("anthropic", AnthropicComputer);
|
|
2209
|
+
NativeComputer.register(
|
|
2210
|
+
"anthropic-computer-20251124",
|
|
2211
|
+
AnthropicComputer20251124
|
|
2212
|
+
);
|
|
2213
|
+
}
|
|
2214
|
+
});
|
|
2215
|
+
|
|
2216
|
+
// src/worlds/nativeComputer/openai.ts
|
|
2217
|
+
function safetyCheck(raw) {
|
|
2218
|
+
const check = { id: String(readField(raw, "id") ?? "") };
|
|
2219
|
+
const code = readField(raw, "code");
|
|
2220
|
+
const message = readField(raw, "message");
|
|
2221
|
+
if (code !== void 0) check.code = String(code);
|
|
2222
|
+
if (message !== void 0) check.message = String(message);
|
|
2223
|
+
return check;
|
|
2224
|
+
}
|
|
2225
|
+
function dataUrl(png) {
|
|
2226
|
+
return `data:image/png;base64,${png.toString("base64")}`;
|
|
2227
|
+
}
|
|
2228
|
+
function xy(raw) {
|
|
2229
|
+
return {
|
|
2230
|
+
x: toInt(readField(raw, "x") ?? 0),
|
|
2231
|
+
y: toInt(readField(raw, "y") ?? 0)
|
|
2232
|
+
};
|
|
2233
|
+
}
|
|
2234
|
+
function held(raw) {
|
|
2235
|
+
return modifierKeys(readField(raw, "keys"));
|
|
2236
|
+
}
|
|
2237
|
+
var WAIT_SECONDS, BUTTONS, HISTORY_BUTTONS, PendingSafetyChecks, ACTIONS, OpenAIComputer, OpenAIPreviewComputer;
|
|
2238
|
+
var init_openai = __esm({
|
|
2239
|
+
"src/worlds/nativeComputer/openai.ts"() {
|
|
2240
|
+
"use strict";
|
|
2241
|
+
init_actions();
|
|
2242
|
+
init_base();
|
|
2243
|
+
init_keys();
|
|
2244
|
+
WAIT_SECONDS = 1;
|
|
2245
|
+
BUTTONS = {
|
|
2246
|
+
left: "left",
|
|
2247
|
+
right: "right",
|
|
2248
|
+
wheel: "middle",
|
|
2249
|
+
middle: "middle"
|
|
2250
|
+
};
|
|
2251
|
+
HISTORY_BUTTONS = /* @__PURE__ */ new Set(["back", "forward"]);
|
|
2252
|
+
PendingSafetyChecks = class extends Error {
|
|
2253
|
+
constructor(callId, checks) {
|
|
2254
|
+
const listed2 = checks.map((c) => `${c.code ?? "check"}: ${c.message ?? ""}`.trim()).join("; ");
|
|
2255
|
+
super(
|
|
2256
|
+
`computer_call ${callId} needs ${checks.length} safety check(s) acknowledged: ${listed2}`
|
|
2257
|
+
);
|
|
2258
|
+
this.callId = callId;
|
|
2259
|
+
this.checks = checks;
|
|
2260
|
+
this.name = "PendingSafetyChecks";
|
|
2261
|
+
}
|
|
2262
|
+
callId;
|
|
2263
|
+
checks;
|
|
2264
|
+
};
|
|
2265
|
+
ACTIONS = {
|
|
2266
|
+
click: (raw) => {
|
|
2267
|
+
const button = String(readField(raw, "button") ?? "left");
|
|
2268
|
+
if (HISTORY_BUTTONS.has(button))
|
|
2269
|
+
return new ComputerAction("history", {
|
|
2270
|
+
direction: button
|
|
2271
|
+
});
|
|
2272
|
+
if (!Object.hasOwn(BUTTONS, button))
|
|
2273
|
+
throw new Error(`unknown mouse button: ${button}`);
|
|
2274
|
+
return new ComputerAction("click", {
|
|
2275
|
+
...xy(raw),
|
|
2276
|
+
button: BUTTONS[button],
|
|
2277
|
+
count: 1,
|
|
2278
|
+
modifiers: held(raw)
|
|
2279
|
+
});
|
|
2280
|
+
},
|
|
2281
|
+
double_click: (raw) => new ComputerAction("click", {
|
|
2282
|
+
...xy(raw),
|
|
2283
|
+
button: "left",
|
|
2284
|
+
count: 2,
|
|
2285
|
+
modifiers: held(raw)
|
|
2286
|
+
}),
|
|
2287
|
+
drag: (raw) => new ComputerAction("drag", {
|
|
2288
|
+
path: (readField(raw, "path") ?? []).map(
|
|
2289
|
+
(p) => [toInt(readField(p, "x")), toInt(readField(p, "y"))]
|
|
2290
|
+
),
|
|
2291
|
+
modifiers: held(raw)
|
|
2292
|
+
}),
|
|
2293
|
+
keypress: (raw) => new ComputerAction("key", {
|
|
2294
|
+
keys: [
|
|
2295
|
+
...KeyChord.fromKeys(readField(raw, "keys") ?? []).keys
|
|
2296
|
+
],
|
|
2297
|
+
repeat: 1
|
|
2298
|
+
}),
|
|
2299
|
+
move: (raw) => new ComputerAction("move", { ...xy(raw), modifiers: held(raw) }),
|
|
2300
|
+
scroll: (raw) => new ComputerAction("scroll", {
|
|
2301
|
+
...xy(raw),
|
|
2302
|
+
dx: toInt(readField(raw, "scroll_x", "scrollX") ?? 0),
|
|
2303
|
+
dy: toInt(readField(raw, "scroll_y", "scrollY") ?? 0),
|
|
2304
|
+
modifiers: held(raw)
|
|
2305
|
+
}),
|
|
2306
|
+
type: (raw) => new ComputerAction("type", { text: String(readField(raw, "text") ?? "") }),
|
|
2307
|
+
wait: () => new ComputerAction("wait", { seconds: WAIT_SECONDS }),
|
|
2308
|
+
screenshot: () => new ComputerAction("screenshot")
|
|
2309
|
+
};
|
|
2310
|
+
OpenAIComputer = class _OpenAIComputer extends NativeComputer {
|
|
2311
|
+
tool() {
|
|
2312
|
+
return { type: "computer" };
|
|
2313
|
+
}
|
|
2314
|
+
owns(item) {
|
|
2315
|
+
return readField(item, "type") === "computer_call";
|
|
2316
|
+
}
|
|
2317
|
+
parse(raw) {
|
|
2318
|
+
const kind = String(readField(raw, "type"));
|
|
2319
|
+
const parser = Object.hasOwn(ACTIONS, kind) ? ACTIONS[kind] : void 0;
|
|
2320
|
+
if (!parser) throw new Error(`unknown computer action: ${kind}`);
|
|
2321
|
+
return parser(raw);
|
|
2322
|
+
}
|
|
2323
|
+
static actionsOf(call3) {
|
|
2324
|
+
const batch = readField(call3, "actions");
|
|
2325
|
+
if (Array.isArray(batch)) return batch;
|
|
2326
|
+
const single = readField(call3, "action");
|
|
2327
|
+
return single === void 0 ? [] : [single];
|
|
2328
|
+
}
|
|
2329
|
+
/** Run a `computer_call`'s actions and return its `computer_call_output`.
|
|
2330
|
+
* Throws `PendingSafetyChecks` (before anything runs) while a check the
|
|
2331
|
+
* model raised is not in `acknowledged`. */
|
|
2332
|
+
async execute(call3, acknowledged = []) {
|
|
2333
|
+
const callId = String(readField(call3, "call_id", "callId"));
|
|
2334
|
+
const checks = (readField(
|
|
2335
|
+
call3,
|
|
2336
|
+
"pending_safety_checks",
|
|
2337
|
+
"pendingSafetyChecks"
|
|
2338
|
+
) ?? []).map(safetyCheck);
|
|
2339
|
+
const png = await this.runCall(
|
|
2340
|
+
callId,
|
|
2341
|
+
_OpenAIComputer.actionsOf(call3),
|
|
2342
|
+
checks,
|
|
2343
|
+
acknowledged
|
|
2344
|
+
);
|
|
2345
|
+
return {
|
|
2346
|
+
type: "computer_call_output",
|
|
2347
|
+
call_id: callId,
|
|
2348
|
+
output: {
|
|
2349
|
+
type: "computer_screenshot",
|
|
2350
|
+
image_url: dataUrl(png),
|
|
2351
|
+
detail: "original"
|
|
2352
|
+
},
|
|
2353
|
+
...checks.length > 0 ? { acknowledged_safety_checks: checks } : {}
|
|
2354
|
+
};
|
|
2355
|
+
}
|
|
2356
|
+
/** For `openai.tools.computer({ ...computer.aiSdk() })`: `execute` runs a
|
|
2357
|
+
* call's `actions` and returns the screenshot output. A call with pending
|
|
2358
|
+
* safety checks asks for approval first (`needsApproval`), so the AI SDK's
|
|
2359
|
+
* approval flow puts them in front of a person; once approved, `execute`
|
|
2360
|
+
* acknowledges them. */
|
|
2361
|
+
aiSdk() {
|
|
2362
|
+
return {
|
|
2363
|
+
needsApproval: (input) => (input.pendingSafetyChecks ?? []).length > 0,
|
|
2364
|
+
execute: (input) => this.serial(async () => {
|
|
2365
|
+
const checks = (input.pendingSafetyChecks ?? []).map(safetyCheck);
|
|
2366
|
+
const png = await this.runCall(
|
|
2367
|
+
"ai-sdk",
|
|
2368
|
+
input.actions ?? [],
|
|
2369
|
+
checks,
|
|
2370
|
+
checks
|
|
2371
|
+
);
|
|
2372
|
+
return {
|
|
2373
|
+
output: { type: "computer_screenshot", imageUrl: dataUrl(png) },
|
|
2374
|
+
...checks.length > 0 ? { acknowledgedSafetyChecks: checks } : {}
|
|
2375
|
+
};
|
|
2376
|
+
})
|
|
2377
|
+
};
|
|
2378
|
+
}
|
|
2379
|
+
/** The batch's actions, run after the safety checks clear; the screen after them. */
|
|
2380
|
+
async runCall(callId, rawActions, checks, acknowledged) {
|
|
2381
|
+
const cleared = new Set(acknowledged.map((c) => safetyCheck(c).id));
|
|
2382
|
+
const waiting = checks.filter((c) => !c.id || !cleared.has(c.id));
|
|
2383
|
+
if (waiting.length > 0) throw new PendingSafetyChecks(callId, waiting);
|
|
2384
|
+
const actions = rawActions.map((raw) => this.parse(raw));
|
|
2385
|
+
const results = await this.performAll(actions);
|
|
2386
|
+
const last = actions.at(-1);
|
|
2387
|
+
if (last?.name === "screenshot")
|
|
2388
|
+
return results.at(-1)?.image ?? Buffer.alloc(0);
|
|
2389
|
+
return this.screenshot();
|
|
2390
|
+
}
|
|
2391
|
+
};
|
|
2392
|
+
OpenAIPreviewComputer = class extends OpenAIComputer {
|
|
2393
|
+
tool() {
|
|
2394
|
+
return {
|
|
2395
|
+
type: "computer_use_preview",
|
|
2396
|
+
display_width: this.display.width,
|
|
2397
|
+
display_height: this.display.height,
|
|
2398
|
+
environment: "browser"
|
|
2399
|
+
};
|
|
2400
|
+
}
|
|
2401
|
+
};
|
|
2402
|
+
NativeComputer.register("openai", OpenAIComputer);
|
|
2403
|
+
NativeComputer.register("openai-preview", OpenAIPreviewComputer);
|
|
2404
|
+
}
|
|
2405
|
+
});
|
|
2406
|
+
|
|
2407
|
+
// src/worlds/nativeComputer/index.ts
|
|
2408
|
+
var init_nativeComputer = __esm({
|
|
2409
|
+
"src/worlds/nativeComputer/index.ts"() {
|
|
2410
|
+
"use strict";
|
|
2411
|
+
init_actions();
|
|
2412
|
+
init_base();
|
|
2413
|
+
init_display();
|
|
2414
|
+
init_keys();
|
|
2415
|
+
init_screen();
|
|
2416
|
+
init_trace();
|
|
2417
|
+
init_anthropic();
|
|
2418
|
+
init_openai();
|
|
2419
|
+
}
|
|
2420
|
+
});
|
|
2421
|
+
|
|
1155
2422
|
// src/worlds/sessionContract.ts
|
|
1156
2423
|
function serializeCallBody(body) {
|
|
1157
2424
|
const text2 = JSON.stringify(body);
|
|
@@ -1205,6 +2472,75 @@ var init_sessionContract = __esm({
|
|
|
1205
2472
|
}
|
|
1206
2473
|
});
|
|
1207
2474
|
|
|
2475
|
+
// src/tracing/session.ts
|
|
2476
|
+
var session_exports = {};
|
|
2477
|
+
__export(session_exports, {
|
|
2478
|
+
SESSION_ID_ATTRIBUTE: () => SESSION_ID_ATTRIBUTE,
|
|
2479
|
+
SessionSpanProcessor: () => SessionSpanProcessor,
|
|
2480
|
+
WORLD_SESSION_ID_ATTRIBUTE: () => WORLD_SESSION_ID_ATTRIBUTE,
|
|
2481
|
+
getAmbientSessionId: () => getAmbientSessionId,
|
|
2482
|
+
getCurrentWorldSessionId: () => getCurrentWorldSessionId,
|
|
2483
|
+
withSession: () => withSession,
|
|
2484
|
+
withWorldSession: () => withWorldSession
|
|
2485
|
+
});
|
|
2486
|
+
function getAmbientSessionId() {
|
|
2487
|
+
return currentSessionStorage.getStore();
|
|
2488
|
+
}
|
|
2489
|
+
function getCurrentWorldSessionId() {
|
|
2490
|
+
return currentWorldSessionStorage.getStore();
|
|
2491
|
+
}
|
|
2492
|
+
function runIn(storage, value, fn) {
|
|
2493
|
+
return new Promise((resolve29, reject) => {
|
|
2494
|
+
storage.run(value, () => {
|
|
2495
|
+
Promise.resolve().then(fn).then(resolve29, reject);
|
|
2496
|
+
});
|
|
2497
|
+
});
|
|
2498
|
+
}
|
|
2499
|
+
function withSession(sessionId, fn) {
|
|
2500
|
+
return runIn(currentSessionStorage, sessionId, fn);
|
|
2501
|
+
}
|
|
2502
|
+
function withWorldSession(worldSessionId, fn) {
|
|
2503
|
+
return runIn(
|
|
2504
|
+
currentWorldSessionStorage,
|
|
2505
|
+
worldSessionId,
|
|
2506
|
+
() => withSession(worldSessionId, fn)
|
|
2507
|
+
);
|
|
2508
|
+
}
|
|
2509
|
+
var import_async_hooks, SESSION_ID_ATTRIBUTE, WORLD_SESSION_ID_ATTRIBUTE, processStorage, currentSessionStorage, currentWorldSessionStorage, SessionSpanProcessor;
|
|
2510
|
+
var init_session = __esm({
|
|
2511
|
+
"src/tracing/session.ts"() {
|
|
2512
|
+
"use strict";
|
|
2513
|
+
import_async_hooks = require("async_hooks");
|
|
2514
|
+
SESSION_ID_ATTRIBUTE = "gateway.session.id";
|
|
2515
|
+
WORLD_SESSION_ID_ATTRIBUTE = "gateway.trace.metadata.world_session_id";
|
|
2516
|
+
processStorage = (name) => {
|
|
2517
|
+
const key2 = /* @__PURE__ */ Symbol.for(`@withgateway/sdk/${name}`);
|
|
2518
|
+
const slots = globalThis;
|
|
2519
|
+
slots[key2] ??= new import_async_hooks.AsyncLocalStorage();
|
|
2520
|
+
return slots[key2];
|
|
2521
|
+
};
|
|
2522
|
+
currentSessionStorage = processStorage("session-storage");
|
|
2523
|
+
currentWorldSessionStorage = processStorage("world-session-storage");
|
|
2524
|
+
SessionSpanProcessor = class {
|
|
2525
|
+
onStart(span, _parentContext) {
|
|
2526
|
+
const worldSessionId = getCurrentWorldSessionId();
|
|
2527
|
+
if (worldSessionId)
|
|
2528
|
+
span.setAttribute(WORLD_SESSION_ID_ATTRIBUTE, worldSessionId);
|
|
2529
|
+
const sessionId = getAmbientSessionId();
|
|
2530
|
+
if (!sessionId || span.attributes?.[SESSION_ID_ATTRIBUTE] !== void 0)
|
|
2531
|
+
return;
|
|
2532
|
+
span.setAttribute(SESSION_ID_ATTRIBUTE, sessionId);
|
|
2533
|
+
}
|
|
2534
|
+
onEnd(_span) {
|
|
2535
|
+
}
|
|
2536
|
+
async shutdown() {
|
|
2537
|
+
}
|
|
2538
|
+
async forceFlush() {
|
|
2539
|
+
}
|
|
2540
|
+
};
|
|
2541
|
+
}
|
|
2542
|
+
});
|
|
2543
|
+
|
|
1208
2544
|
// src/worlds/taskRef.ts
|
|
1209
2545
|
var isTaskIdRef, isTaskSpec, taskLabel, assertTaskRef;
|
|
1210
2546
|
var init_taskRef = __esm({
|
|
@@ -1229,8 +2565,8 @@ var init_taskRef = __esm({
|
|
|
1229
2565
|
});
|
|
1230
2566
|
|
|
1231
2567
|
// src/worlds/session.ts
|
|
1232
|
-
var
|
|
1233
|
-
__export(
|
|
2568
|
+
var session_exports2 = {};
|
|
2569
|
+
__export(session_exports2, {
|
|
1234
2570
|
WorldSession: () => WorldSession,
|
|
1235
2571
|
WorldSessionCallError: () => WorldSessionCallError,
|
|
1236
2572
|
WorldSessionTimeout: () => WorldSessionTimeout,
|
|
@@ -1283,7 +2619,7 @@ function schemaFromSignature(spec) {
|
|
|
1283
2619
|
};
|
|
1284
2620
|
const inside = /\(([\s\S]*)\)\s*$/.exec(spec.signature.trim())?.[1] ?? "";
|
|
1285
2621
|
const properties = {};
|
|
1286
|
-
const
|
|
2622
|
+
const required2 = [];
|
|
1287
2623
|
const params = [];
|
|
1288
2624
|
let depth = 0;
|
|
1289
2625
|
let current = "";
|
|
@@ -1304,7 +2640,7 @@ function schemaFromSignature(spec) {
|
|
|
1304
2640
|
if (!name) continue;
|
|
1305
2641
|
if (eq === -1) {
|
|
1306
2642
|
properties[name] = { type: "string" };
|
|
1307
|
-
|
|
2643
|
+
required2.push(name);
|
|
1308
2644
|
continue;
|
|
1309
2645
|
}
|
|
1310
2646
|
const value = param.slice(eq + 1).trim();
|
|
@@ -1318,7 +2654,7 @@ function schemaFromSignature(spec) {
|
|
|
1318
2654
|
function: {
|
|
1319
2655
|
name: modelToolName(spec.name),
|
|
1320
2656
|
description: spec.doc ?? spec.name,
|
|
1321
|
-
parameters: { type: "object", properties, required }
|
|
2657
|
+
parameters: { type: "object", properties, required: required2 }
|
|
1322
2658
|
}
|
|
1323
2659
|
};
|
|
1324
2660
|
}
|
|
@@ -1387,13 +2723,16 @@ async function runSessions(opts) {
|
|
|
1387
2723
|
task = taskLabel(taskRef, session.taskInfo);
|
|
1388
2724
|
await session.ready();
|
|
1389
2725
|
const toolkit = await session.toolkit();
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
2726
|
+
const live = session;
|
|
2727
|
+
await live.withTraceContext(
|
|
2728
|
+
() => opts.agent({
|
|
2729
|
+
session: live,
|
|
2730
|
+
toolkit,
|
|
2731
|
+
instruction: live.instruction ?? (isTaskSpec(taskRef) ? taskRef.instruction : task),
|
|
2732
|
+
task,
|
|
2733
|
+
taskRef
|
|
2734
|
+
})
|
|
2735
|
+
);
|
|
1397
2736
|
const graded = await session.grade();
|
|
1398
2737
|
const result = {
|
|
1399
2738
|
task,
|
|
@@ -1430,14 +2769,16 @@ async function runSessions(opts) {
|
|
|
1430
2769
|
passed: failed2 === 0 && (opts.failUnder === void 0 || mean >= opts.failUnder)
|
|
1431
2770
|
};
|
|
1432
2771
|
}
|
|
1433
|
-
var
|
|
1434
|
-
var
|
|
2772
|
+
var import_node_crypto2, READY_TIMEOUT_MS, READY_POLL_MS, CALL_TIMEOUT_MS, CALL_POLL_MS, JUDGED_GRADE_TIMEOUT_MS, JUDGED_GRADE_POLL_MS, EXPORT_PAGE, sleep, modelToolName, WorldSessionTimeout, WorldSessionCallError, WorldSession, OPEN_SESSION_OPTION_KEYS, isOpenSessionOptions;
|
|
2773
|
+
var init_session2 = __esm({
|
|
1435
2774
|
"src/worlds/session.ts"() {
|
|
1436
2775
|
"use strict";
|
|
1437
|
-
|
|
2776
|
+
import_node_crypto2 = require("crypto");
|
|
1438
2777
|
init_worlds();
|
|
1439
2778
|
init_browser();
|
|
2779
|
+
init_nativeComputer();
|
|
1440
2780
|
init_sessionContract();
|
|
2781
|
+
init_session();
|
|
1441
2782
|
init_taskRef();
|
|
1442
2783
|
init_taskRef();
|
|
1443
2784
|
READY_TIMEOUT_MS = 10 * 6e4;
|
|
@@ -1571,7 +2912,7 @@ var init_session = __esm({
|
|
|
1571
2912
|
/** The reporter `browser()` uses; exposed for a page you drive yourself. */
|
|
1572
2913
|
browserRecorder(agentId) {
|
|
1573
2914
|
const path44 = `/api/public/world-sessions/${encodeURIComponent(this.sessionId)}/browser-events`;
|
|
1574
|
-
const id = agentId ?? process.env.GATEWAY_AGENT_ID ?? `agent-${(0,
|
|
2915
|
+
const id = agentId ?? process.env.GATEWAY_AGENT_ID ?? `agent-${(0, import_node_crypto2.randomUUID)().replace(/-/g, "").slice(0, 8)}`;
|
|
1575
2916
|
return new BrowserActionRecorder(
|
|
1576
2917
|
async (events) => {
|
|
1577
2918
|
await apiRequest(this.options, "POST", path44, { events });
|
|
@@ -1591,6 +2932,12 @@ var init_session = __esm({
|
|
|
1591
2932
|
computerUseTools(browser) {
|
|
1592
2933
|
return computerUseToolkit(browser);
|
|
1593
2934
|
}
|
|
2935
|
+
/** The browser as a provider's own pixel-based computer-use tool: `anthropic`
|
|
2936
|
+
* (`computer_toolset_20260801`), `openai` (Responses `computer`),
|
|
2937
|
+
* `anthropic-computer-20251124` or `openai-preview`. See `nativeComputer/`. */
|
|
2938
|
+
nativeComputer(browser, provider = "anthropic", options = {}) {
|
|
2939
|
+
return NativeComputer.forProvider(provider, browser, options);
|
|
2940
|
+
}
|
|
1594
2941
|
/** The session's latest platform state (one request, no waiting). */
|
|
1595
2942
|
async status() {
|
|
1596
2943
|
const fresh = await apiRequest(
|
|
@@ -1642,18 +2989,18 @@ var init_session = __esm({
|
|
|
1642
2989
|
const pollMs3 = judged ? JUDGED_GRADE_POLL_MS : CALL_POLL_MS;
|
|
1643
2990
|
const deadline = Date.now() + budgetMs;
|
|
1644
2991
|
for (; ; ) {
|
|
1645
|
-
const
|
|
2992
|
+
const call3 = await apiRequest(
|
|
1646
2993
|
this.options,
|
|
1647
2994
|
"GET",
|
|
1648
2995
|
`/api/public/world-sessions/${encodeURIComponent(this.sessionId)}/calls/${encodeURIComponent(callId)}`
|
|
1649
2996
|
);
|
|
1650
|
-
if (
|
|
1651
|
-
if (
|
|
1652
|
-
return
|
|
2997
|
+
if (call3.done) {
|
|
2998
|
+
if (call3.error) throw new WorldSessionCallError(call3.error);
|
|
2999
|
+
return call3.result;
|
|
1653
3000
|
}
|
|
1654
3001
|
if (Date.now() > deadline)
|
|
1655
3002
|
throw new WorldSessionTimeout(
|
|
1656
|
-
judged ? `Grade ${callId} still ${
|
|
3003
|
+
judged ? `Grade ${callId} still ${call3.state} after ${Math.round(budgetMs / 1e3)}s \u2014 the judge has not answered; the platform finalizes the call on its own, read it back with export().` : `Call ${callId} still ${call3.state} after ${Math.round(budgetMs / 1e3)}s \u2014 the container may have died.`
|
|
1657
3004
|
);
|
|
1658
3005
|
await sleep(pollMs3);
|
|
1659
3006
|
}
|
|
@@ -1766,15 +3113,15 @@ var init_session = __esm({
|
|
|
1766
3113
|
"GET",
|
|
1767
3114
|
`/api/public/world-sessions/${encodeURIComponent(this.sessionId)}/calls?${params.toString()}`
|
|
1768
3115
|
);
|
|
1769
|
-
for (const
|
|
3116
|
+
for (const call3 of page.calls) {
|
|
1770
3117
|
calls.push({
|
|
1771
|
-
seq: Number(
|
|
1772
|
-
kind: String(
|
|
1773
|
-
tool: typeof
|
|
1774
|
-
args:
|
|
1775
|
-
result:
|
|
1776
|
-
error: typeof
|
|
1777
|
-
completedAt: typeof
|
|
3118
|
+
seq: Number(call3.seq),
|
|
3119
|
+
kind: String(call3.kind ?? "call"),
|
|
3120
|
+
tool: typeof call3.tool === "string" ? call3.tool : null,
|
|
3121
|
+
args: call3.args ?? null,
|
|
3122
|
+
result: call3.result ?? null,
|
|
3123
|
+
error: typeof call3.error === "string" ? call3.error : null,
|
|
3124
|
+
completedAt: typeof call3.completedAt === "string" ? call3.completedAt : null
|
|
1778
3125
|
});
|
|
1779
3126
|
}
|
|
1780
3127
|
cursor = page.nextCursor ?? void 0;
|
|
@@ -1825,6 +3172,21 @@ var init_session = __esm({
|
|
|
1825
3172
|
{ keepWarm: opts.keepWarm ?? false }
|
|
1826
3173
|
);
|
|
1827
3174
|
}
|
|
3175
|
+
/**
|
|
3176
|
+
* Run `fn` as work inside this session: spans it records take `sessionId`
|
|
3177
|
+
* as their session id and carry `world_session_id` trace metadata, so the
|
|
3178
|
+
* agent's traces land in the same session as the platform's traces of this
|
|
3179
|
+
* session's tool calls. A `withSession()` block inside still wins for the
|
|
3180
|
+
* session id. No effect before `tracing.init()`. `runSessions` wraps each
|
|
3181
|
+
* agent call in it.
|
|
3182
|
+
*
|
|
3183
|
+
* ```typescript
|
|
3184
|
+
* await session.withTraceContext(() => myAgent(toolkit, session.instruction));
|
|
3185
|
+
* ```
|
|
3186
|
+
*/
|
|
3187
|
+
withTraceContext(fn) {
|
|
3188
|
+
return withWorldSession(this.sessionId, fn);
|
|
3189
|
+
}
|
|
1828
3190
|
};
|
|
1829
3191
|
OPEN_SESSION_OPTION_KEYS = /* @__PURE__ */ new Set([
|
|
1830
3192
|
"task",
|
|
@@ -1974,7 +3336,11 @@ function fromResponse(answer, options) {
|
|
|
1974
3336
|
const worlds = {};
|
|
1975
3337
|
for (const [alias, state2] of Object.entries(answer.sessions)) {
|
|
1976
3338
|
sessions[alias] = new WorldSession(state2.sessionId, state2, options);
|
|
1977
|
-
worlds[alias] = {
|
|
3339
|
+
worlds[alias] = {
|
|
3340
|
+
slug: state2.slug,
|
|
3341
|
+
ref: state2.ref,
|
|
3342
|
+
private: state2.private ?? null
|
|
3343
|
+
};
|
|
1978
3344
|
}
|
|
1979
3345
|
return new TaskSessions(
|
|
1980
3346
|
answer.taskId,
|
|
@@ -2048,6 +3414,7 @@ async function attachTask(taskId, options = {}) {
|
|
|
2048
3414
|
{
|
|
2049
3415
|
slug: row.slug ?? "",
|
|
2050
3416
|
ref: null,
|
|
3417
|
+
private: null,
|
|
2051
3418
|
versionId: row.versionId,
|
|
2052
3419
|
sessionId: row.sessionId,
|
|
2053
3420
|
ready: row.ready,
|
|
@@ -2077,7 +3444,7 @@ async function attachManifest(manifest, options = {}) {
|
|
|
2077
3444
|
Object.fromEntries(
|
|
2078
3445
|
Object.entries(manifest.sessions).map(([alias, entry]) => [
|
|
2079
3446
|
alias,
|
|
2080
|
-
{ slug: entry.slug, ref: entry.ref }
|
|
3447
|
+
{ slug: entry.slug, ref: entry.ref, private: entry.private ?? null }
|
|
2081
3448
|
])
|
|
2082
3449
|
)
|
|
2083
3450
|
);
|
|
@@ -2091,12 +3458,13 @@ var init_taskSessions = __esm({
|
|
|
2091
3458
|
"use strict";
|
|
2092
3459
|
init_worlds();
|
|
2093
3460
|
init_browser();
|
|
2094
|
-
|
|
3461
|
+
init_session2();
|
|
2095
3462
|
TASK_SESSIONS = "/api/public/world-task-sessions";
|
|
2096
3463
|
VERIFIER_REWARD_PREFIX = "x.";
|
|
2097
3464
|
manifestSession = (s, state2, world) => ({
|
|
2098
3465
|
slug: world.slug,
|
|
2099
3466
|
ref: world.ref,
|
|
3467
|
+
private: world.private,
|
|
2100
3468
|
versionId: state2.versionId,
|
|
2101
3469
|
sessionId: state2.sessionId,
|
|
2102
3470
|
ready: state2.ready,
|
|
@@ -2131,10 +3499,10 @@ var init_taskSessions = __esm({
|
|
|
2131
3499
|
sessions;
|
|
2132
3500
|
worlds;
|
|
2133
3501
|
hash;
|
|
2134
|
-
/** This alias's
|
|
2135
|
-
*
|
|
3502
|
+
/** This alias's world as recorded at open/attach — what a `TaskRun`
|
|
3503
|
+
* filing needs to name, without exposing the whole map. */
|
|
2136
3504
|
worldRef(alias) {
|
|
2137
|
-
return this.worlds[alias] ?? { slug: "", ref: null };
|
|
3505
|
+
return this.worlds[alias] ?? { slug: "", ref: null, private: null };
|
|
2138
3506
|
}
|
|
2139
3507
|
/** The aliases, in the spec's order. */
|
|
2140
3508
|
get aliases() {
|
|
@@ -2504,15 +3872,15 @@ function resolveUserId() {
|
|
|
2504
3872
|
const envUser = process.env.GATEWAY_USER_ID?.trim();
|
|
2505
3873
|
return envUser ? envUser : void 0;
|
|
2506
3874
|
}
|
|
2507
|
-
var
|
|
3875
|
+
var import_async_hooks2, import_api, USER_ID_ATTRIBUTE, currentUserStorage, IdentitySpanProcessor;
|
|
2508
3876
|
var init_identity = __esm({
|
|
2509
3877
|
"src/tracing/identity.ts"() {
|
|
2510
3878
|
"use strict";
|
|
2511
|
-
|
|
3879
|
+
import_async_hooks2 = require("async_hooks");
|
|
2512
3880
|
import_api = require("@opentelemetry/api");
|
|
2513
3881
|
init_users();
|
|
2514
3882
|
USER_ID_ATTRIBUTE = "gateway.user.id";
|
|
2515
|
-
currentUserStorage = new
|
|
3883
|
+
currentUserStorage = new import_async_hooks2.AsyncLocalStorage();
|
|
2516
3884
|
IdentitySpanProcessor = class {
|
|
2517
3885
|
onStart(span, _parentContext) {
|
|
2518
3886
|
const userId = resolveUserId();
|
|
@@ -2530,43 +3898,224 @@ var init_identity = __esm({
|
|
|
2530
3898
|
}
|
|
2531
3899
|
});
|
|
2532
3900
|
|
|
2533
|
-
// src/tracing/
|
|
2534
|
-
|
|
2535
|
-
|
|
2536
|
-
|
|
2537
|
-
|
|
2538
|
-
|
|
2539
|
-
|
|
2540
|
-
}
|
|
2541
|
-
|
|
2542
|
-
return
|
|
3901
|
+
// src/tracing/secrets.ts
|
|
3902
|
+
function jsonOrUndefined(text2) {
|
|
3903
|
+
let parsed;
|
|
3904
|
+
try {
|
|
3905
|
+
parsed = JSON.parse(text2);
|
|
3906
|
+
} catch {
|
|
3907
|
+
return void 0;
|
|
3908
|
+
}
|
|
3909
|
+
if (typeof parsed === "string") return parsed;
|
|
3910
|
+
return parsed !== null && typeof parsed === "object" ? parsed : void 0;
|
|
2543
3911
|
}
|
|
2544
|
-
function
|
|
2545
|
-
return
|
|
2546
|
-
|
|
2547
|
-
|
|
2548
|
-
|
|
3912
|
+
function encodings(value) {
|
|
3913
|
+
return [value, percentEncoded(value), JSON.stringify(value).slice(1, -1)];
|
|
3914
|
+
}
|
|
3915
|
+
function percentEncoded(value) {
|
|
3916
|
+
try {
|
|
3917
|
+
return encodeURIComponent(value);
|
|
3918
|
+
} catch {
|
|
3919
|
+
return value;
|
|
3920
|
+
}
|
|
3921
|
+
}
|
|
3922
|
+
function union(sets) {
|
|
3923
|
+
return new Set(sets.flatMap((set) => [...set]));
|
|
3924
|
+
}
|
|
3925
|
+
function leaves(value) {
|
|
3926
|
+
if (typeof value === "string") {
|
|
3927
|
+
return [...value].length >= MIN_SECRET_LENGTH ? /* @__PURE__ */ new Set([value]) : /* @__PURE__ */ new Set();
|
|
3928
|
+
}
|
|
3929
|
+
if (Array.isArray(value)) return union(value.map(leaves));
|
|
3930
|
+
if (value === null || typeof value !== "object") return /* @__PURE__ */ new Set();
|
|
3931
|
+
return union(Object.values(value).map(leaves));
|
|
3932
|
+
}
|
|
3933
|
+
function sameAttributes(before, after) {
|
|
3934
|
+
const keys = Object.keys(before);
|
|
3935
|
+
if (keys.length !== Object.keys(after).length) return false;
|
|
3936
|
+
return keys.every(
|
|
3937
|
+
(key2) => before[key2] === after[key2] || sameArray(before[key2], after[key2])
|
|
3938
|
+
);
|
|
3939
|
+
}
|
|
3940
|
+
function sameArray(before, after) {
|
|
3941
|
+
if (!Array.isArray(before) || !Array.isArray(after)) return false;
|
|
3942
|
+
return before.length === after.length && before.every((item, i) => item === after[i]);
|
|
3943
|
+
}
|
|
3944
|
+
function scrubbedRead(reads, property) {
|
|
3945
|
+
return typeof property === "string" && property in reads ? reads[property] : void 0;
|
|
3946
|
+
}
|
|
3947
|
+
function viewOf(span, reads) {
|
|
3948
|
+
const view = new Proxy(span, {
|
|
3949
|
+
get(target, property) {
|
|
3950
|
+
const read = scrubbedRead(reads, property);
|
|
3951
|
+
if (read) return read();
|
|
3952
|
+
const value = Reflect.get(target, property, target);
|
|
3953
|
+
if (typeof value !== "function") return value;
|
|
3954
|
+
return (...args) => {
|
|
3955
|
+
const result = value.apply(target, args);
|
|
3956
|
+
return result === target ? view : result;
|
|
3957
|
+
};
|
|
3958
|
+
},
|
|
3959
|
+
getOwnPropertyDescriptor(target, property) {
|
|
3960
|
+
const descriptor = Reflect.getOwnPropertyDescriptor(target, property);
|
|
3961
|
+
const read = scrubbedRead(reads, property);
|
|
3962
|
+
if (!read || !descriptor || !("value" in descriptor)) return descriptor;
|
|
3963
|
+
return { ...descriptor, value: read() };
|
|
3964
|
+
}
|
|
2549
3965
|
});
|
|
3966
|
+
return view;
|
|
2550
3967
|
}
|
|
2551
|
-
var
|
|
2552
|
-
var
|
|
2553
|
-
"src/tracing/
|
|
3968
|
+
var SECRET_KEYS, REDACTED2, MIN_SECRET_LENGTH, SpanSecrets, SPAN_SECRETS, SecretRedactingSpanProcessor;
|
|
3969
|
+
var init_secrets = __esm({
|
|
3970
|
+
"src/tracing/secrets.ts"() {
|
|
2554
3971
|
"use strict";
|
|
2555
|
-
|
|
2556
|
-
|
|
2557
|
-
|
|
2558
|
-
|
|
2559
|
-
|
|
2560
|
-
|
|
2561
|
-
|
|
2562
|
-
|
|
3972
|
+
SECRET_KEYS = /* @__PURE__ */ new Set([
|
|
3973
|
+
"authorization_token",
|
|
3974
|
+
"authorizationToken"
|
|
3975
|
+
]);
|
|
3976
|
+
REDACTED2 = "[redacted: holds a credential]";
|
|
3977
|
+
MIN_SECRET_LENGTH = 8;
|
|
3978
|
+
SpanSecrets = class {
|
|
3979
|
+
constructor(keys = SECRET_KEYS) {
|
|
3980
|
+
this.keys = keys;
|
|
3981
|
+
}
|
|
3982
|
+
keys;
|
|
3983
|
+
isSecret(key2) {
|
|
3984
|
+
return this.keys.has(key2);
|
|
3985
|
+
}
|
|
3986
|
+
drops(attribute) {
|
|
3987
|
+
return this.mentions(attribute);
|
|
3988
|
+
}
|
|
3989
|
+
strip(value) {
|
|
3990
|
+
if (typeof value === "string") return this.stripNested(value);
|
|
3991
|
+
if (Array.isArray(value)) return value.map((item) => this.strip(item));
|
|
3992
|
+
if (value === null || typeof value !== "object") return value;
|
|
3993
|
+
return Object.fromEntries(
|
|
3994
|
+
Object.entries(value).filter(([key2]) => !this.isSecret(key2)).map(([key2, item]) => [key2, this.strip(item)])
|
|
3995
|
+
);
|
|
3996
|
+
}
|
|
3997
|
+
scrubAttribute(value) {
|
|
3998
|
+
try {
|
|
3999
|
+
return this.scrubbedValue(value);
|
|
4000
|
+
} catch {
|
|
4001
|
+
return Array.isArray(value) ? [REDACTED2] : REDACTED2;
|
|
4002
|
+
}
|
|
4003
|
+
}
|
|
4004
|
+
scrubbedValue(value) {
|
|
4005
|
+
if (typeof value === "string") return this.scrubbedText(value);
|
|
4006
|
+
if (!Array.isArray(value)) return value;
|
|
4007
|
+
const results = value.map(
|
|
4008
|
+
(item) => typeof item === "string" ? this.cleaned(item) : { text: item, removed: /* @__PURE__ */ new Set() }
|
|
4009
|
+
);
|
|
4010
|
+
const removed = new Set(results.flatMap((r) => [...r.removed]));
|
|
4011
|
+
const scrubbed = results.map((r) => r.text);
|
|
4012
|
+
const withheld = scrubbed.some(
|
|
4013
|
+
(item) => typeof item === "string" && this.carries(item, removed)
|
|
4014
|
+
);
|
|
4015
|
+
return withheld ? [REDACTED2] : scrubbed;
|
|
4016
|
+
}
|
|
4017
|
+
scrubAttributes(attributes) {
|
|
4018
|
+
return Object.fromEntries(
|
|
4019
|
+
Object.entries(attributes).filter(([key2]) => !this.drops(key2)).map(([key2, value]) => [key2, this.scrubAttribute(value)])
|
|
4020
|
+
);
|
|
4021
|
+
}
|
|
4022
|
+
mentions(text2) {
|
|
4023
|
+
return [...this.keys].some((key2) => text2.includes(key2));
|
|
4024
|
+
}
|
|
4025
|
+
scrubbedText(text2) {
|
|
4026
|
+
const { text: cleaned, removed } = this.cleaned(text2);
|
|
4027
|
+
return this.carries(cleaned, removed) ? REDACTED2 : cleaned;
|
|
4028
|
+
}
|
|
4029
|
+
cleaned(text2) {
|
|
4030
|
+
if (!this.mentions(text2)) return { text: text2, removed: /* @__PURE__ */ new Set() };
|
|
4031
|
+
const parsed = jsonOrUndefined(text2);
|
|
4032
|
+
if (parsed === void 0) return { text: REDACTED2, removed: /* @__PURE__ */ new Set() };
|
|
4033
|
+
return {
|
|
4034
|
+
text: JSON.stringify(this.strip(parsed)),
|
|
4035
|
+
removed: this.removed(parsed)
|
|
4036
|
+
};
|
|
4037
|
+
}
|
|
4038
|
+
carries(text2, removed) {
|
|
4039
|
+
if (text2 === REDACTED2 || this.mentions(text2)) return true;
|
|
4040
|
+
return [...removed].some(
|
|
4041
|
+
(value) => encodings(value).some((form) => text2.includes(form))
|
|
4042
|
+
);
|
|
4043
|
+
}
|
|
4044
|
+
removed(value) {
|
|
4045
|
+
if (typeof value === "string") {
|
|
4046
|
+
const nested = this.mentions(value) ? jsonOrUndefined(value) : void 0;
|
|
4047
|
+
return nested === void 0 ? /* @__PURE__ */ new Set() : this.removed(nested);
|
|
2563
4048
|
}
|
|
4049
|
+
if (Array.isArray(value)) return union(value.map((v) => this.removed(v)));
|
|
4050
|
+
if (value === null || typeof value !== "object") return /* @__PURE__ */ new Set();
|
|
4051
|
+
return union(
|
|
4052
|
+
Object.entries(value).map(
|
|
4053
|
+
([key2, item]) => this.isSecret(key2) ? leaves(item) : this.removed(item)
|
|
4054
|
+
)
|
|
4055
|
+
);
|
|
4056
|
+
}
|
|
4057
|
+
stripNested(text2) {
|
|
4058
|
+
if (!this.mentions(text2)) return text2;
|
|
4059
|
+
const parsed = jsonOrUndefined(text2);
|
|
4060
|
+
if (parsed === void 0) return text2;
|
|
4061
|
+
return JSON.stringify(this.strip(parsed));
|
|
4062
|
+
}
|
|
4063
|
+
};
|
|
4064
|
+
SPAN_SECRETS = new SpanSecrets();
|
|
4065
|
+
SecretRedactingSpanProcessor = class {
|
|
4066
|
+
constructor(inner, secrets = SPAN_SECRETS) {
|
|
4067
|
+
this.inner = inner;
|
|
4068
|
+
this.secrets = secrets;
|
|
4069
|
+
}
|
|
4070
|
+
inner;
|
|
4071
|
+
secrets;
|
|
4072
|
+
views = /* @__PURE__ */ new WeakMap();
|
|
4073
|
+
onStart(span, parentContext) {
|
|
4074
|
+
this.inner.onStart(this.viewFor(span), parentContext);
|
|
4075
|
+
}
|
|
4076
|
+
onEnd(span) {
|
|
4077
|
+
const view = this.viewFor(span);
|
|
4078
|
+
try {
|
|
4079
|
+
void [view.attributes, view.events, view.status];
|
|
4080
|
+
} catch (error) {
|
|
4081
|
+
console.warn(
|
|
4082
|
+
`[gatewaysdk.tracing] Dropped span "${span.name}": could not redact it: ${error?.name}`
|
|
4083
|
+
);
|
|
4084
|
+
return;
|
|
4085
|
+
}
|
|
4086
|
+
this.inner.onEnd(view);
|
|
4087
|
+
}
|
|
4088
|
+
viewFor(span) {
|
|
4089
|
+
const known = this.views.get(span);
|
|
4090
|
+
if (known) return known;
|
|
4091
|
+
const view = viewOf(span, {
|
|
4092
|
+
attributes: () => this.scrubbedAttributes(span.attributes),
|
|
4093
|
+
events: () => span.events.map((event) => this.scrubbedEvent(event)),
|
|
4094
|
+
status: () => this.scrubbedStatus(span.status)
|
|
4095
|
+
});
|
|
4096
|
+
this.views.set(span, view);
|
|
4097
|
+
return view;
|
|
4098
|
+
}
|
|
4099
|
+
forceFlush() {
|
|
4100
|
+
return this.inner.forceFlush();
|
|
2564
4101
|
}
|
|
2565
|
-
|
|
4102
|
+
shutdown() {
|
|
4103
|
+
return this.inner.shutdown();
|
|
2566
4104
|
}
|
|
2567
|
-
|
|
4105
|
+
scrubbedAttributes(attributes) {
|
|
4106
|
+
const clean2 = this.secrets.scrubAttributes(attributes);
|
|
4107
|
+
return sameAttributes(attributes, clean2) ? attributes : clean2;
|
|
2568
4108
|
}
|
|
2569
|
-
|
|
4109
|
+
scrubbedStatus(status) {
|
|
4110
|
+
if (!status.message) return status;
|
|
4111
|
+
const message = this.secrets.scrubAttribute(status.message);
|
|
4112
|
+
return message === status.message ? status : { ...status, message };
|
|
4113
|
+
}
|
|
4114
|
+
scrubbedEvent(event) {
|
|
4115
|
+
if (!event.attributes) return event;
|
|
4116
|
+
const attributes = this.scrubbedAttributes(event.attributes);
|
|
4117
|
+
if (attributes === event.attributes) return event;
|
|
4118
|
+
return { ...event, attributes };
|
|
2570
4119
|
}
|
|
2571
4120
|
};
|
|
2572
4121
|
}
|
|
@@ -2591,14 +4140,14 @@ function coerceSignalValue(value) {
|
|
|
2591
4140
|
return { numericValue: value, inferredType: "NUMERIC" };
|
|
2592
4141
|
}
|
|
2593
4142
|
async function success(name, value = true, options = {}) {
|
|
2594
|
-
let
|
|
4143
|
+
let client4;
|
|
2595
4144
|
try {
|
|
2596
|
-
|
|
4145
|
+
client4 = ScoresClient.fromEnv();
|
|
2597
4146
|
} catch (error) {
|
|
2598
4147
|
console.warn(`[gateway.scores] success '${name}' skipped`, error);
|
|
2599
4148
|
return;
|
|
2600
4149
|
}
|
|
2601
|
-
await
|
|
4150
|
+
await client4.success(name, value, options);
|
|
2602
4151
|
}
|
|
2603
4152
|
var import_api2, SUCCESS_SIGNAL_KEY, SUCCESS_METRIC_NAME_KEY, AGENT_ID_KEY, ScoreError, ScoresClient, scores;
|
|
2604
4153
|
var init_scores = __esm({
|
|
@@ -2793,7 +4342,7 @@ var require_package = __commonJS({
|
|
|
2793
4342
|
"package.json"(exports2, module2) {
|
|
2794
4343
|
module2.exports = {
|
|
2795
4344
|
name: "@withgateway/sdk",
|
|
2796
|
-
version: "0.
|
|
4345
|
+
version: "0.3.0",
|
|
2797
4346
|
description: "Gateway SDK for TypeScript - A/B experiments, tracing, and observability",
|
|
2798
4347
|
main: "./dist/index.js",
|
|
2799
4348
|
module: "./dist/index.mjs",
|
|
@@ -3004,7 +4553,7 @@ function canonicalJson(value) {
|
|
|
3004
4553
|
return `{${entries.map(([k, v]) => `${JSON.stringify(k)}:${canonicalJson(v)}`).join(",")}}`;
|
|
3005
4554
|
}
|
|
3006
4555
|
function sha256(text2) {
|
|
3007
|
-
return `sha256:${(0,
|
|
4556
|
+
return `sha256:${(0, import_node_crypto3.createHash)("sha256").update(text2).digest("hex")}`;
|
|
3008
4557
|
}
|
|
3009
4558
|
function getRegisteredTools() {
|
|
3010
4559
|
return [...registeredTools.values()].sort(
|
|
@@ -3179,11 +4728,11 @@ async function registerBuild(params) {
|
|
|
3179
4728
|
);
|
|
3180
4729
|
}
|
|
3181
4730
|
}
|
|
3182
|
-
var
|
|
4731
|
+
var import_node_crypto3, registeredTools, registeredPrompts, registeredSkills, registeredArtifacts, activeBuilds;
|
|
3183
4732
|
var init_build = __esm({
|
|
3184
4733
|
"src/build/index.ts"() {
|
|
3185
4734
|
"use strict";
|
|
3186
|
-
|
|
4735
|
+
import_node_crypto3 = require("crypto");
|
|
3187
4736
|
registeredTools = /* @__PURE__ */ new Map();
|
|
3188
4737
|
registeredPrompts = /* @__PURE__ */ new Map();
|
|
3189
4738
|
registeredSkills = /* @__PURE__ */ new Map();
|
|
@@ -3313,7 +4862,7 @@ function buildProvider(config, logFn) {
|
|
|
3313
4862
|
const spanProcessors = [];
|
|
3314
4863
|
if (config.customSpanProcessors) {
|
|
3315
4864
|
for (const sp of config.customSpanProcessors) {
|
|
3316
|
-
spanProcessors.push(sp);
|
|
4865
|
+
spanProcessors.push(new SecretRedactingSpanProcessor(sp));
|
|
3317
4866
|
logFn(
|
|
3318
4867
|
"Added custom span processor: %s",
|
|
3319
4868
|
sp.constructor?.name ?? "unknown"
|
|
@@ -3332,7 +4881,11 @@ function buildProvider(config, logFn) {
|
|
|
3332
4881
|
if (config.batch?.maxExportBatchSize) {
|
|
3333
4882
|
batchConfig.maxExportBatchSize = config.batch.maxExportBatchSize;
|
|
3334
4883
|
}
|
|
3335
|
-
spanProcessors.push(
|
|
4884
|
+
spanProcessors.push(
|
|
4885
|
+
new SecretRedactingSpanProcessor(
|
|
4886
|
+
new BatchSpanProcessor(exporter, batchConfig)
|
|
4887
|
+
)
|
|
4888
|
+
);
|
|
3336
4889
|
let provider = new NodeTracerProvider({
|
|
3337
4890
|
resource: createResource(resourceAttrs)
|
|
3338
4891
|
});
|
|
@@ -3470,7 +5023,8 @@ var init_init = __esm({
|
|
|
3470
5023
|
"src/tracing/init.ts"() {
|
|
3471
5024
|
"use strict";
|
|
3472
5025
|
init_identity();
|
|
3473
|
-
|
|
5026
|
+
init_secrets();
|
|
5027
|
+
init_session();
|
|
3474
5028
|
init_scores();
|
|
3475
5029
|
init_build();
|
|
3476
5030
|
ENV_VARS = {
|
|
@@ -3585,7 +5139,7 @@ function reportFromResult(result) {
|
|
|
3585
5139
|
return { report, extra };
|
|
3586
5140
|
}
|
|
3587
5141
|
async function runTask(ref, agent, opts) {
|
|
3588
|
-
const runId = `wtr-${(0,
|
|
5142
|
+
const runId = `wtr-${(0, import_node_crypto4.randomBytes)(6).toString("hex")}`;
|
|
3589
5143
|
const outDir = opts.outDir ?? "runs";
|
|
3590
5144
|
const runDir = path.join(outDir, runId);
|
|
3591
5145
|
fs.mkdirSync(runDir, { recursive: true });
|
|
@@ -3623,7 +5177,7 @@ async function runTask(ref, agent, opts) {
|
|
|
3623
5177
|
let extra = {};
|
|
3624
5178
|
try {
|
|
3625
5179
|
const invoke = () => agent(taskRun);
|
|
3626
|
-
const result = traced ? await (await Promise.resolve().then(() => (
|
|
5180
|
+
const result = traced ? await (await Promise.resolve().then(() => (init_session(), session_exports))).withSession(runId, invoke) : await invoke();
|
|
3627
5181
|
({ report, extra } = reportFromResult(result));
|
|
3628
5182
|
} catch (error) {
|
|
3629
5183
|
const message = (error instanceof Error ? error.message : String(error)) || "Unknown error";
|
|
@@ -3690,16 +5244,16 @@ async function runTask(ref, agent, opts) {
|
|
|
3690
5244
|
}
|
|
3691
5245
|
}
|
|
3692
5246
|
}
|
|
3693
|
-
var
|
|
5247
|
+
var import_node_crypto4, fs, path, TaskRun, describeValue, RESULT_CONTRACT;
|
|
3694
5248
|
var init_taskRun = __esm({
|
|
3695
5249
|
"src/worlds/taskRun.ts"() {
|
|
3696
5250
|
"use strict";
|
|
3697
|
-
|
|
5251
|
+
import_node_crypto4 = require("crypto");
|
|
3698
5252
|
fs = __toESM(require("fs"));
|
|
3699
5253
|
path = __toESM(require("path"));
|
|
3700
5254
|
init_browser();
|
|
3701
5255
|
init_evals();
|
|
3702
|
-
|
|
5256
|
+
init_session2();
|
|
3703
5257
|
init_taskSessions();
|
|
3704
5258
|
TaskRun = class {
|
|
3705
5259
|
constructor(runId, instruction, model, sessions, manifest) {
|
|
@@ -4008,11 +5562,11 @@ var init_checkoutTarget = __esm({
|
|
|
4008
5562
|
});
|
|
4009
5563
|
|
|
4010
5564
|
// src/worlds/worldDir.ts
|
|
4011
|
-
var
|
|
5565
|
+
var import_node_crypto5, fs3, path3, WORLD_MANIFEST, API_BUNDLE_MANIFEST, BUNDLED_WORLD_PREFIX, CONNECTOR_SPEC, PYPROJECT, BENCHMARK_CONFIG, WORLD_SCHEMA_MARKERS, WORLD_ROOT_MARKERS, BROAD_ROOT_MARKERS, SKIPPED_DIRS, V1_DEP, V1_IMPORT, V1_TASKSET, HARBOR_TASK, skippedDir, byCodePoint, WorldDir;
|
|
4012
5566
|
var init_worldDir = __esm({
|
|
4013
5567
|
"src/worlds/worldDir.ts"() {
|
|
4014
5568
|
"use strict";
|
|
4015
|
-
|
|
5569
|
+
import_node_crypto5 = require("crypto");
|
|
4016
5570
|
fs3 = __toESM(require("fs"));
|
|
4017
5571
|
path3 = __toESM(require("path"));
|
|
4018
5572
|
WORLD_MANIFEST = "gateway-env.toml";
|
|
@@ -4118,7 +5672,7 @@ var init_worldDir = __esm({
|
|
|
4118
5672
|
* sorted order: the version's identity, byte-compatible with
|
|
4119
5673
|
* `_archive.compute_content_hash` and Prime Intellect. */
|
|
4120
5674
|
get contentHash() {
|
|
4121
|
-
const hasher = (0,
|
|
5675
|
+
const hasher = (0, import_node_crypto5.createHash)("sha256");
|
|
4122
5676
|
for (const rel of this.archivePaths) {
|
|
4123
5677
|
hasher.update(Buffer.from(`file:${rel}`, "utf-8"));
|
|
4124
5678
|
hasher.update(fs3.readFileSync(path3.join(this.dir, rel)));
|
|
@@ -4422,7 +5976,7 @@ function writeLocalMeta(dir, meta) {
|
|
|
4422
5976
|
function snapshotTreeHashes(dir) {
|
|
4423
5977
|
const out = {};
|
|
4424
5978
|
for (const relPath of collectArchiveRelPaths(dir)) {
|
|
4425
|
-
out[relPath] = (0,
|
|
5979
|
+
out[relPath] = (0, import_node_crypto6.createHash)("sha256").update(fs5.readFileSync(path5.join(dir, relPath))).digest("hex");
|
|
4426
5980
|
}
|
|
4427
5981
|
return out;
|
|
4428
5982
|
}
|
|
@@ -4468,7 +6022,7 @@ function buildFileManifest(dir) {
|
|
|
4468
6022
|
path: relPath,
|
|
4469
6023
|
isDirectory: false,
|
|
4470
6024
|
size: payload.length,
|
|
4471
|
-
sha256: (0,
|
|
6025
|
+
sha256: (0, import_node_crypto6.createHash)("sha256").update(payload).digest("hex")
|
|
4472
6026
|
};
|
|
4473
6027
|
});
|
|
4474
6028
|
}
|
|
@@ -4667,11 +6221,11 @@ async function createRef(slug, name, kind, versionId, options = {}) {
|
|
|
4667
6221
|
...versionId ? { versionId } : {}
|
|
4668
6222
|
});
|
|
4669
6223
|
}
|
|
4670
|
-
var
|
|
6224
|
+
var import_node_crypto6, import_node_zlib2, fs5, path5, DEFAULT_BRANCH, META_RELPATH, FILE_MODE, MINTED_SUFFIX, PushSlugConflict, sha256b64, DetachedPushError;
|
|
4671
6225
|
var init_hub = __esm({
|
|
4672
6226
|
"src/worlds/hub.ts"() {
|
|
4673
6227
|
"use strict";
|
|
4674
|
-
|
|
6228
|
+
import_node_crypto6 = require("crypto");
|
|
4675
6229
|
import_node_zlib2 = require("zlib");
|
|
4676
6230
|
fs5 = __toESM(require("fs"));
|
|
4677
6231
|
path5 = __toESM(require("path"));
|
|
@@ -4697,7 +6251,7 @@ var init_hub = __esm({
|
|
|
4697
6251
|
tracked;
|
|
4698
6252
|
declared;
|
|
4699
6253
|
};
|
|
4700
|
-
sha256b64 = (data) => (0,
|
|
6254
|
+
sha256b64 = (data) => (0, import_node_crypto6.createHash)("sha256").update(data).digest("base64");
|
|
4701
6255
|
DetachedPushError = class extends Error {
|
|
4702
6256
|
constructor(dir, tag) {
|
|
4703
6257
|
super(
|
|
@@ -5352,11 +6906,11 @@ function applyTransforms(value, chain) {
|
|
|
5352
6906
|
for (const step of steps) out = step(out);
|
|
5353
6907
|
return out;
|
|
5354
6908
|
}
|
|
5355
|
-
var
|
|
6909
|
+
var import_node_crypto7, WHITESPACE, WHITESPACE_EDGES, WHITESPACE_RUN, NOT_DIGIT, STRIP_PREFIX, trim, emailLocalPart, emailDomain, stripPrefix, hex, SIMPLE, TRANSFORMS, text;
|
|
5356
6910
|
var init_transforms = __esm({
|
|
5357
6911
|
"src/worlds/transforms.ts"() {
|
|
5358
6912
|
"use strict";
|
|
5359
|
-
|
|
6913
|
+
import_node_crypto7 = require("crypto");
|
|
5360
6914
|
init_json();
|
|
5361
6915
|
WHITESPACE = " \n\r\f\v";
|
|
5362
6916
|
WHITESPACE_EDGES = new RegExp(`^[${WHITESPACE}]+|[${WHITESPACE}]+$`, "g");
|
|
@@ -5373,7 +6927,7 @@ var init_transforms = __esm({
|
|
|
5373
6927
|
return at === -1 ? "" : value.slice(at + 1).toLowerCase();
|
|
5374
6928
|
};
|
|
5375
6929
|
stripPrefix = (prefix) => (value) => value.startsWith(prefix) ? value.slice(prefix.length) : value;
|
|
5376
|
-
hex = (algorithm, value) => (0,
|
|
6930
|
+
hex = (algorithm, value) => (0, import_node_crypto7.createHash)(algorithm).update(value, "utf8").digest("hex");
|
|
5377
6931
|
SIMPLE = {
|
|
5378
6932
|
lower: (value) => value.toLowerCase(),
|
|
5379
6933
|
upper: (value) => value.toUpperCase(),
|
|
@@ -5405,7 +6959,7 @@ function pyText(value) {
|
|
|
5405
6959
|
return pyFloatRepr(value);
|
|
5406
6960
|
}
|
|
5407
6961
|
function hashForm(slug, plaintext) {
|
|
5408
|
-
return "sha256:" + (0,
|
|
6962
|
+
return "sha256:" + (0, import_node_crypto8.createHash)("sha256").update(`${slug}:${pyText(plaintext)}`, "utf8").digest("hex");
|
|
5409
6963
|
}
|
|
5410
6964
|
function preserveForm(slug, plaintext) {
|
|
5411
6965
|
const kind = typeof plaintext === "string" ? "str" : isInt(plaintext) ? "int" : "float";
|
|
@@ -5414,12 +6968,12 @@ function preserveForm(slug, plaintext) {
|
|
|
5414
6968
|
}
|
|
5415
6969
|
function shapeText(slug, text2, kind) {
|
|
5416
6970
|
const seed = Buffer.from(`${slug}:${text2}`, "utf8");
|
|
5417
|
-
let digest2 = (0,
|
|
6971
|
+
let digest2 = (0, import_node_crypto8.createHash)("sha256").update(seed).digest();
|
|
5418
6972
|
let cursor = 0;
|
|
5419
6973
|
const out = [];
|
|
5420
6974
|
for (const char of text2) {
|
|
5421
6975
|
if (cursor === digest2.length) {
|
|
5422
|
-
digest2 = (0,
|
|
6976
|
+
digest2 = (0, import_node_crypto8.createHash)("sha256").update(Buffer.concat([digest2, seed])).digest();
|
|
5423
6977
|
cursor = 0;
|
|
5424
6978
|
}
|
|
5425
6979
|
const byte = digest2[cursor];
|
|
@@ -5456,11 +7010,11 @@ function storedForms(world, field2, plaintext, transform) {
|
|
|
5456
7010
|
if (policy !== null) return [roundForm(plaintext, world.redact.round[field2])];
|
|
5457
7011
|
return [plaintext];
|
|
5458
7012
|
}
|
|
5459
|
-
var
|
|
7013
|
+
var import_node_crypto8, isInt;
|
|
5460
7014
|
var init_redaction = __esm({
|
|
5461
7015
|
"src/worlds/redaction.ts"() {
|
|
5462
7016
|
"use strict";
|
|
5463
|
-
|
|
7017
|
+
import_node_crypto8 = require("crypto");
|
|
5464
7018
|
init_json();
|
|
5465
7019
|
init_transforms();
|
|
5466
7020
|
isInt = (value) => typeof value === "number" && Number.isInteger(value);
|
|
@@ -6261,9 +7815,9 @@ __export(transform_exports, {
|
|
|
6261
7815
|
});
|
|
6262
7816
|
function checkRows(value, where) {
|
|
6263
7817
|
if (!isObject2(value)) throw new CliError(`${where} must return {entity: [rows]}; got ${value === null ? "null" : Array.isArray(value) ? "an array" : typeof value}`, 1);
|
|
6264
|
-
for (const [entity,
|
|
6265
|
-
if (!Array.isArray(
|
|
6266
|
-
|
|
7818
|
+
for (const [entity, listed2] of Object.entries(value)) {
|
|
7819
|
+
if (!Array.isArray(listed2)) throw new CliError(`${where}: ${entity} must be a list of rows; got ${listed2 === null ? "null" : typeof listed2}`, 1);
|
|
7820
|
+
listed2.forEach((row, index2) => {
|
|
6267
7821
|
if (!isObject2(row)) throw new CliError(`${where}: ${entity}[${index2}] is not an object`, 1);
|
|
6268
7822
|
});
|
|
6269
7823
|
}
|
|
@@ -6440,7 +7994,7 @@ function uploadHeadersFor(gz) {
|
|
|
6440
7994
|
return {
|
|
6441
7995
|
"content-type": "application/gzip",
|
|
6442
7996
|
"content-length": String(gz.length),
|
|
6443
|
-
"x-amz-checksum-sha256": (0,
|
|
7997
|
+
"x-amz-checksum-sha256": (0, import_node_crypto9.createHash)("sha256").update(gz).digest("base64")
|
|
6444
7998
|
};
|
|
6445
7999
|
}
|
|
6446
8000
|
async function forEachLimited(items, limit, fn) {
|
|
@@ -6466,12 +8020,12 @@ async function forEachLimited(items, limit, fn) {
|
|
|
6466
8020
|
await Promise.all(inFlight);
|
|
6467
8021
|
if (failure) throw failure;
|
|
6468
8022
|
}
|
|
6469
|
-
async function waitForBatch(
|
|
6470
|
-
const sleep4 = opts.sleep ??
|
|
8023
|
+
async function waitForBatch(client4, batchId, opts = {}) {
|
|
8024
|
+
const sleep4 = opts.sleep ?? client4.sleep;
|
|
6471
8025
|
let delay = opts.initialDelayMs ?? 1e3;
|
|
6472
8026
|
let last = "";
|
|
6473
8027
|
for (; ; ) {
|
|
6474
|
-
const status = await
|
|
8028
|
+
const status = await client4.get(batchId);
|
|
6475
8029
|
const phase = phaseLine(status);
|
|
6476
8030
|
if (phase !== last) {
|
|
6477
8031
|
opts.onPhase?.(phase);
|
|
@@ -6507,11 +8061,11 @@ async function writeRefusalReport(status, file) {
|
|
|
6507
8061
|
fs10.writeFileSync(file, text2);
|
|
6508
8062
|
return text2 ? text2.split("\n").filter(Boolean).length : 0;
|
|
6509
8063
|
}
|
|
6510
|
-
var
|
|
8064
|
+
var import_node_crypto9, fs10, TERMINAL_STATES, sleepMs, slugOf, WorldDataApi;
|
|
6511
8065
|
var init_batches = __esm({
|
|
6512
8066
|
"src/cli/platform/worldData/batches.ts"() {
|
|
6513
8067
|
"use strict";
|
|
6514
|
-
|
|
8068
|
+
import_node_crypto9 = require("crypto");
|
|
6515
8069
|
fs10 = __toESM(require("fs"));
|
|
6516
8070
|
init_config();
|
|
6517
8071
|
init_router();
|
|
@@ -6706,12 +8260,12 @@ function finishChunk(ordinal, raw, rows, entity, firstRow = 0) {
|
|
|
6706
8260
|
const gz = gzipDeterministic(raw, { name: chunkName(ordinal) });
|
|
6707
8261
|
return {
|
|
6708
8262
|
ordinal,
|
|
6709
|
-
digest: (0,
|
|
8263
|
+
digest: (0, import_node_crypto10.createHash)("sha256").update(gz).digest("hex"),
|
|
6710
8264
|
bytes: gz.length,
|
|
6711
8265
|
rows,
|
|
6712
8266
|
entity,
|
|
6713
8267
|
rawBytes: raw.length,
|
|
6714
|
-
contentSha256: (0,
|
|
8268
|
+
contentSha256: (0, import_node_crypto10.createHash)("sha256").update(raw).digest("hex"),
|
|
6715
8269
|
firstRow,
|
|
6716
8270
|
gz
|
|
6717
8271
|
};
|
|
@@ -6773,11 +8327,11 @@ function parseSize(text2) {
|
|
|
6773
8327
|
);
|
|
6774
8328
|
return Number(m[1]) * units[m[2]];
|
|
6775
8329
|
}
|
|
6776
|
-
var
|
|
8330
|
+
var import_node_crypto10, import_node_zlib3, DEFAULT_CHUNK_BYTES, GZIP_LEVEL, chunkName, table;
|
|
6777
8331
|
var init_chunker = __esm({
|
|
6778
8332
|
"src/cli/platform/worldData/chunker.ts"() {
|
|
6779
8333
|
"use strict";
|
|
6780
|
-
|
|
8334
|
+
import_node_crypto10 = require("crypto");
|
|
6781
8335
|
import_node_zlib3 = require("zlib");
|
|
6782
8336
|
init_json();
|
|
6783
8337
|
DEFAULT_CHUNK_BYTES = 64 * 1024 * 1024;
|
|
@@ -6793,8 +8347,8 @@ __export(push_exports, {
|
|
|
6793
8347
|
pushRows: () => pushRows
|
|
6794
8348
|
});
|
|
6795
8349
|
async function pushRows(creds, slug, rows, opts = {}) {
|
|
6796
|
-
const
|
|
6797
|
-
const opened = await
|
|
8350
|
+
const client4 = opts.sleep ? new WorldDataApi(creds, slug, opts.sleep) : new WorldDataApi(creds, slug);
|
|
8351
|
+
const opened = await client4.open({
|
|
6798
8352
|
mode: opts.mode ?? "append",
|
|
6799
8353
|
merge: "upsert",
|
|
6800
8354
|
...opts.redact && opts.redact !== "off" ? { redact: opts.redact } : {},
|
|
@@ -6805,16 +8359,16 @@ async function pushRows(creds, slug, rows, opts = {}) {
|
|
|
6805
8359
|
});
|
|
6806
8360
|
if (!opened.batchId) throw new Error("the platform opened no batch (no batchId in the answer)");
|
|
6807
8361
|
const tagged = (async function* () {
|
|
6808
|
-
for (const [entity,
|
|
6809
|
-
for (let index2 = 0; index2 <
|
|
6810
|
-
yield { entity, row: parseJson(JSON.stringify(
|
|
8362
|
+
for (const [entity, listed2] of Object.entries(rows))
|
|
8363
|
+
for (let index2 = 0; index2 < listed2.length; index2++)
|
|
8364
|
+
yield { entity, row: parseJson(JSON.stringify(listed2[index2])), where: `${entity}[${index2}]` };
|
|
6811
8365
|
})();
|
|
6812
8366
|
const chunks = buildChunks(tagged, { chunkBytes: opts.chunkBytes ?? DEFAULT_CHUNK_BYTES, chunkRows: null, entity: null });
|
|
6813
8367
|
await forEachLimited(chunks, Math.max(1, opts.parallel ?? 4), async (chunk) => {
|
|
6814
|
-
await
|
|
8368
|
+
await client4.upload(opened.batchId, chunk);
|
|
6815
8369
|
});
|
|
6816
|
-
await
|
|
6817
|
-
return waitForBatch(
|
|
8370
|
+
await client4.complete(opened.batchId);
|
|
8371
|
+
return waitForBatch(client4, opened.batchId, { initialDelayMs: pollMs() });
|
|
6818
8372
|
}
|
|
6819
8373
|
function pollMs() {
|
|
6820
8374
|
const raw = Number(process.env.GATEWAY_WORLD_DATA_POLL_MS ?? 1e3);
|
|
@@ -6868,12 +8422,12 @@ function toolCallRecordsIn(text2, where) {
|
|
|
6868
8422
|
const stripped = text2.trim();
|
|
6869
8423
|
if (!stripped) return [];
|
|
6870
8424
|
if (stripped.startsWith("[")) {
|
|
6871
|
-
const
|
|
6872
|
-
if (!Array.isArray(
|
|
6873
|
-
|
|
8425
|
+
const listed2 = JSON.parse(stripped);
|
|
8426
|
+
if (!Array.isArray(listed2)) throw new Error(`${where} is neither a JSON array nor JSON Lines`);
|
|
8427
|
+
listed2.forEach((item, index2) => {
|
|
6874
8428
|
if (!isObject3(item)) throw new Error(`${where}[${index2}] is not an object`);
|
|
6875
8429
|
});
|
|
6876
|
-
return
|
|
8430
|
+
return listed2;
|
|
6877
8431
|
}
|
|
6878
8432
|
const records2 = [];
|
|
6879
8433
|
const lines = text2.split(/\r?\n/);
|
|
@@ -7031,7 +8585,7 @@ function transformReport(world, records2, rows, stderr, outcome) {
|
|
|
7031
8585
|
ingested: records2,
|
|
7032
8586
|
skipped: {},
|
|
7033
8587
|
refusals: [],
|
|
7034
|
-
rows: Object.fromEntries(Object.entries(rows).map(([entity,
|
|
8588
|
+
rows: Object.fromEntries(Object.entries(rows).map(([entity, listed2]) => [entity, listed2.length])),
|
|
7035
8589
|
dryRun: outcome.dryRun,
|
|
7036
8590
|
redact: outcome.redact,
|
|
7037
8591
|
changed: outcome.changed,
|
|
@@ -7083,7 +8637,7 @@ var init_ingest = __esm({
|
|
|
7083
8637
|
});
|
|
7084
8638
|
|
|
7085
8639
|
// src/worlds/editSessions.ts
|
|
7086
|
-
var WORLDS, WorldEditClient;
|
|
8640
|
+
var WORLDS, WorldEditClient, TASK_EDITS, TaskEditClient;
|
|
7087
8641
|
var init_editSessions = __esm({
|
|
7088
8642
|
"src/worlds/editSessions.ts"() {
|
|
7089
8643
|
"use strict";
|
|
@@ -7115,6 +8669,22 @@ var init_editSessions = __esm({
|
|
|
7115
8669
|
return apiRequest(this.options, "POST", `${WORLDS}/${encodeURIComponent(slug)}/edits/rollback`, input);
|
|
7116
8670
|
}
|
|
7117
8671
|
};
|
|
8672
|
+
TASK_EDITS = "/api/public/world-task-edits";
|
|
8673
|
+
TaskEditClient = class {
|
|
8674
|
+
constructor(options = {}) {
|
|
8675
|
+
this.options = options;
|
|
8676
|
+
}
|
|
8677
|
+
options;
|
|
8678
|
+
status(task) {
|
|
8679
|
+
return apiRequest(this.options, "POST", `${TASK_EDITS}/status`, { task });
|
|
8680
|
+
}
|
|
8681
|
+
close(task, input = {}) {
|
|
8682
|
+
return apiRequest(this.options, "POST", `${TASK_EDITS}/close`, { task, ...input });
|
|
8683
|
+
}
|
|
8684
|
+
rollback(task, input) {
|
|
8685
|
+
return apiRequest(this.options, "POST", `${TASK_EDITS}/rollback`, { task, ...input });
|
|
8686
|
+
}
|
|
8687
|
+
};
|
|
7118
8688
|
}
|
|
7119
8689
|
});
|
|
7120
8690
|
|
|
@@ -7210,6 +8780,10 @@ var init_dryRun = __esm({
|
|
|
7210
8780
|
// src/worlds/index.ts
|
|
7211
8781
|
var worlds_exports = {};
|
|
7212
8782
|
__export(worlds_exports, {
|
|
8783
|
+
ACTION_NAMES: () => ACTION_NAMES,
|
|
8784
|
+
ActionTracer: () => ActionTracer,
|
|
8785
|
+
AnthropicComputer: () => AnthropicComputer,
|
|
8786
|
+
AnthropicComputer20251124: () => AnthropicComputer20251124,
|
|
7213
8787
|
ApiError: () => ApiError,
|
|
7214
8788
|
BROWSER_GONE_PATTERNS: () => BROWSER_GONE_PATTERNS,
|
|
7215
8789
|
BROWSER_TIERS: () => BROWSER_TIERS,
|
|
@@ -7221,11 +8795,13 @@ __export(worlds_exports, {
|
|
|
7221
8795
|
CALL_BODY_LIMIT_LABEL: () => CALL_BODY_LIMIT_LABEL,
|
|
7222
8796
|
COMPUTER_USE_SPECS: () => COMPUTER_USE_SPECS,
|
|
7223
8797
|
CheckoutProvenance: () => CheckoutProvenance,
|
|
8798
|
+
ComputerAction: () => ComputerAction,
|
|
7224
8799
|
DEFAULT_BRANCH: () => DEFAULT_BRANCH,
|
|
7225
8800
|
DEFAULT_VIEWPORT: () => DEFAULT_VIEWPORT,
|
|
7226
8801
|
DRY_RUN_AGENT: () => DRY_RUN_AGENT,
|
|
7227
8802
|
DRY_RUN_KIND: () => DRY_RUN_KIND,
|
|
7228
8803
|
DetachedPushError: () => DetachedPushError,
|
|
8804
|
+
Display: () => Display,
|
|
7229
8805
|
DryRunOutcome: () => DryRunOutcome,
|
|
7230
8806
|
EVENT_BATCH_SIZE: () => EVENT_BATCH_SIZE,
|
|
7231
8807
|
EVENT_FLUSH_INTERVAL_MS: () => EVENT_FLUSH_INTERVAL_MS,
|
|
@@ -7235,19 +8811,30 @@ __export(worlds_exports, {
|
|
|
7235
8811
|
GatewayEvalsClient: () => GatewayEvalsClient,
|
|
7236
8812
|
HostedDryRunClient: () => HostedDryRunClient,
|
|
7237
8813
|
IDLE_WARNING_MINUTES: () => IDLE_WARNING_MINUTES,
|
|
8814
|
+
KEY_NAMES: () => KEY_NAMES,
|
|
8815
|
+
KeyChord: () => KeyChord,
|
|
8816
|
+
NOT_EXECUTED: () => NOT_EXECUTED,
|
|
7238
8817
|
NO_GRADER_REASON: () => NO_GRADER_REASON,
|
|
8818
|
+
NativeComputer: () => NativeComputer,
|
|
8819
|
+
OpenAIComputer: () => OpenAIComputer,
|
|
8820
|
+
OpenAIPreviewComputer: () => OpenAIPreviewComputer,
|
|
7239
8821
|
PLATFORM_TIMEOUT_DEFAULT_MS: () => PLATFORM_TIMEOUT_DEFAULT_MS,
|
|
7240
8822
|
PLATFORM_TIMEOUT_ENV: () => PLATFORM_TIMEOUT_ENV,
|
|
8823
|
+
PendingSafetyChecks: () => PendingSafetyChecks,
|
|
7241
8824
|
PlatformTransport: () => PlatformTransport,
|
|
7242
8825
|
PushSlugConflict: () => PushSlugConflict,
|
|
7243
8826
|
RECOVER_BUDGET_MS: () => RECOVER_BUDGET_MS,
|
|
7244
8827
|
SANDBOX_REQUEST_TIMEOUT_MS: () => SANDBOX_REQUEST_TIMEOUT_MS,
|
|
8828
|
+
SECRET_KEY: () => SECRET_KEY,
|
|
7245
8829
|
SESSION_STATES: () => SESSION_STATES,
|
|
8830
|
+
SPAN_PREFIX: () => SPAN_PREFIX,
|
|
7246
8831
|
STATUS_WAIT_CAP_SECONDS: () => STATUS_WAIT_CAP_SECONDS,
|
|
7247
8832
|
STRIP_PREFIX: () => STRIP_PREFIX,
|
|
7248
8833
|
SURFACE_KINDS: () => SURFACE_KINDS,
|
|
8834
|
+
Screen: () => Screen,
|
|
7249
8835
|
SecretScrubber: () => SecretScrubber,
|
|
7250
8836
|
TRANSFORMS: () => TRANSFORMS,
|
|
8837
|
+
TaskEditClient: () => TaskEditClient,
|
|
7251
8838
|
TaskRun: () => TaskRun,
|
|
7252
8839
|
TaskSessions: () => TaskSessions,
|
|
7253
8840
|
TransportCause: () => TransportCause,
|
|
@@ -7320,6 +8907,7 @@ __export(worlds_exports, {
|
|
|
7320
8907
|
parseTransform: () => parseTransform,
|
|
7321
8908
|
parseWorldTaskRefs: () => parseWorldTaskRefs,
|
|
7322
8909
|
platformTimeoutMs: () => platformTimeoutMs,
|
|
8910
|
+
playwrightKey: () => playwrightKey,
|
|
7323
8911
|
preserveForm: () => preserveForm,
|
|
7324
8912
|
propose: () => propose,
|
|
7325
8913
|
pull: () => pull,
|
|
@@ -7329,6 +8917,7 @@ __export(worlds_exports, {
|
|
|
7329
8917
|
pyText: () => pyText,
|
|
7330
8918
|
queryRows: () => queryRows,
|
|
7331
8919
|
queryRowsSearch: () => queryRowsSearch,
|
|
8920
|
+
readField: () => readField,
|
|
7332
8921
|
readLocalMeta: () => readLocalMeta,
|
|
7333
8922
|
readToolCallRecords: () => readToolCallRecords,
|
|
7334
8923
|
rebaseConflicts: () => rebaseConflicts,
|
|
@@ -7578,7 +9167,7 @@ var init_worlds = __esm({
|
|
|
7578
9167
|
"use strict";
|
|
7579
9168
|
init_transport();
|
|
7580
9169
|
init_transport();
|
|
7581
|
-
|
|
9170
|
+
init_session2();
|
|
7582
9171
|
init_sessionList();
|
|
7583
9172
|
init_sessionContract();
|
|
7584
9173
|
init_taskRef();
|
|
@@ -7590,6 +9179,7 @@ var init_worlds = __esm({
|
|
|
7590
9179
|
init_evals();
|
|
7591
9180
|
init_browser();
|
|
7592
9181
|
init_browserReconnect();
|
|
9182
|
+
init_nativeComputer();
|
|
7593
9183
|
init_hub();
|
|
7594
9184
|
init_validate();
|
|
7595
9185
|
init_describe();
|
|
@@ -7656,7 +9246,7 @@ var init_worlds = __esm({
|
|
|
7656
9246
|
* worlds/session.ts.
|
|
7657
9247
|
*/
|
|
7658
9248
|
async open(task, opts = {}) {
|
|
7659
|
-
const { openSession: openSession2 } = await Promise.resolve().then(() => (
|
|
9249
|
+
const { openSession: openSession2 } = await Promise.resolve().then(() => (init_session2(), session_exports2));
|
|
7660
9250
|
return openSession2(this.slug, {
|
|
7661
9251
|
task,
|
|
7662
9252
|
versionId: this.version.versionId,
|
|
@@ -8621,7 +10211,7 @@ async function confirmUpload(options = {}, fileId, ok = true) {
|
|
|
8621
10211
|
return apiRequest(options, "POST", `${BASE}/confirm`, { fileId, ok });
|
|
8622
10212
|
}
|
|
8623
10213
|
async function sha256Base64(localPath) {
|
|
8624
|
-
const hash = (0,
|
|
10214
|
+
const hash = (0, import_node_crypto15.createHash)("sha256");
|
|
8625
10215
|
for await (const chunk of fs32.createReadStream(localPath)) hash.update(chunk);
|
|
8626
10216
|
return hash.digest("base64");
|
|
8627
10217
|
}
|
|
@@ -8674,7 +10264,7 @@ async function uploadBytes(options = {}, bytes, targetPath, upload = {}) {
|
|
|
8674
10264
|
if (!bytes.length) throw new Error("nothing to upload: the content is empty");
|
|
8675
10265
|
const target = drivePath(targetPath);
|
|
8676
10266
|
const contentType = upload.contentType ?? contentTypeFor(target);
|
|
8677
|
-
const sha2562 = (0,
|
|
10267
|
+
const sha2562 = (0, import_node_crypto15.createHash)("sha256").update(bytes).digest("base64");
|
|
8678
10268
|
const granted = await requestUpload(options, { path: target, contentLength: bytes.length, contentType, sha256: sha2562, ...upload.overwrite ? { overwrite: true } : {} });
|
|
8679
10269
|
try {
|
|
8680
10270
|
await putPresigned(granted.uploadUrl, new Uint8Array(bytes), { contentType, contentLength: bytes.length, sha256: sha2562 });
|
|
@@ -8709,11 +10299,11 @@ async function listFileConnectors(options = {}) {
|
|
|
8709
10299
|
async function syncFileConnector(options = {}, connectorId) {
|
|
8710
10300
|
return apiRequest(options, "POST", `${BASE}/connectors/sync`, { connectorId });
|
|
8711
10301
|
}
|
|
8712
|
-
var
|
|
10302
|
+
var import_node_crypto15, fs32, path23, import_node_stream, import_promises, DRIVE_PREFIX, BASE, CONTENT_TYPES;
|
|
8713
10303
|
var init_files = __esm({
|
|
8714
10304
|
"src/files/index.ts"() {
|
|
8715
10305
|
"use strict";
|
|
8716
|
-
|
|
10306
|
+
import_node_crypto15 = require("crypto");
|
|
8717
10307
|
fs32 = __toESM(require("fs"));
|
|
8718
10308
|
path23 = __toESM(require("path"));
|
|
8719
10309
|
import_node_stream = require("stream");
|
|
@@ -9766,10 +11356,10 @@ function swapValue(text2, needle, replacement) {
|
|
|
9766
11356
|
}
|
|
9767
11357
|
|
|
9768
11358
|
// src/hooks/standInDigits.ts
|
|
9769
|
-
var
|
|
11359
|
+
var import_node_crypto11 = require("crypto");
|
|
9770
11360
|
function standInDigits(realDigits, identityName) {
|
|
9771
11361
|
if (!realDigits) return "";
|
|
9772
|
-
const digest2 = (0,
|
|
11362
|
+
const digest2 = (0, import_node_crypto11.createHash)("sha256").update(`${identityName}:${realDigits}`).digest("hex");
|
|
9773
11363
|
let digits = "";
|
|
9774
11364
|
for (let i = 0; i < realDigits.length; i++)
|
|
9775
11365
|
digits += String(parseInt(digest2[i % digest2.length], 16) % 10);
|
|
@@ -9803,7 +11393,7 @@ var DeclaredStandIn = class _DeclaredStandIn {
|
|
|
9803
11393
|
};
|
|
9804
11394
|
|
|
9805
11395
|
// src/hooks/alias.ts
|
|
9806
|
-
var
|
|
11396
|
+
var import_node_crypto12 = require("crypto");
|
|
9807
11397
|
var GIVEN = [
|
|
9808
11398
|
"John",
|
|
9809
11399
|
"Mary",
|
|
@@ -9982,7 +11572,7 @@ function findKind(kind, text2) {
|
|
|
9982
11572
|
return out;
|
|
9983
11573
|
}
|
|
9984
11574
|
function newRunKey() {
|
|
9985
|
-
return (0,
|
|
11575
|
+
return (0, import_node_crypto12.randomBytes)(32).toString("hex");
|
|
9986
11576
|
}
|
|
9987
11577
|
function canonical(kind, value) {
|
|
9988
11578
|
const text2 = String(value).normalize("NFKC").trim();
|
|
@@ -10039,7 +11629,7 @@ function explodeIp(text2) {
|
|
|
10039
11629
|
return groups.map((g) => g.padStart(4, "0")).join(":") + zone;
|
|
10040
11630
|
}
|
|
10041
11631
|
function index(runKey, kind, value, salt = "") {
|
|
10042
|
-
const digest2 = (0,
|
|
11632
|
+
const digest2 = (0, import_node_crypto12.createHmac)("sha256", Buffer.from(runKey, "hex")).update(`${kind}:${value}:${salt}`, "utf8").digest();
|
|
10043
11633
|
return digest2.readBigUInt64BE(0);
|
|
10044
11634
|
}
|
|
10045
11635
|
var pick = (pool, n) => pool[Number(n % BigInt(pool.length))];
|
|
@@ -10063,7 +11653,7 @@ function nameParts(name) {
|
|
|
10063
11653
|
function format(template, parts2) {
|
|
10064
11654
|
return template.replace(/\{(\w+)\}/g, (_, key2) => parts2[key2] ?? "").trim();
|
|
10065
11655
|
}
|
|
10066
|
-
var
|
|
11656
|
+
var pair2 = (real, fake, template) => [
|
|
10067
11657
|
format(template, real),
|
|
10068
11658
|
format(template, fake)
|
|
10069
11659
|
];
|
|
@@ -10123,7 +11713,7 @@ function namePairs(real, fake) {
|
|
|
10123
11713
|
const out = [[real, fake]];
|
|
10124
11714
|
if (realParts.given && realParts.surname) {
|
|
10125
11715
|
for (const template of NAME_FORMS) {
|
|
10126
|
-
const p =
|
|
11716
|
+
const p = pair2(realParts, fakeParts, template);
|
|
10127
11717
|
if (p[0].length > 2 && !p[0].includes("{")) out.push(p);
|
|
10128
11718
|
}
|
|
10129
11719
|
}
|
|
@@ -10161,7 +11751,7 @@ function emailPairs(real, fake) {
|
|
|
10161
11751
|
};
|
|
10162
11752
|
const out = [[real, fake]];
|
|
10163
11753
|
for (const template of EMAIL_FORMS) {
|
|
10164
|
-
const p =
|
|
11754
|
+
const p = pair2(realParts, fakeParts, template);
|
|
10165
11755
|
if (p[0].length > 2) out.push(p);
|
|
10166
11756
|
}
|
|
10167
11757
|
return dedupe(out);
|
|
@@ -10573,7 +12163,7 @@ var AliasMap = class _AliasMap {
|
|
|
10573
12163
|
const existing = this.aliases.get(key2);
|
|
10574
12164
|
if (existing) return existing.display;
|
|
10575
12165
|
if (this.aliasDigests.has(digest2.toLowerCase())) return digest2;
|
|
10576
|
-
const standIn = "sha256:" + (0,
|
|
12166
|
+
const standIn = "sha256:" + (0, import_node_crypto12.createHmac)("sha256", Buffer.from(this.runKey, "hex")).update(digest2, "utf8").digest("hex");
|
|
10577
12167
|
this.aliasDigests.add(standIn.toLowerCase());
|
|
10578
12168
|
const alias = {
|
|
10579
12169
|
kind: "digest",
|
|
@@ -10612,9 +12202,9 @@ var AliasMap = class _AliasMap {
|
|
|
10612
12202
|
});
|
|
10613
12203
|
if (alias.role === "private") {
|
|
10614
12204
|
for (const slug of this.slugs) {
|
|
10615
|
-
const standIn = "sha256:" + (0,
|
|
12205
|
+
const standIn = "sha256:" + (0, import_node_crypto12.createHash)("sha256").update(`${slug}:${canonical(alias.kind, alias.display)}`, "utf8").digest("hex");
|
|
10616
12206
|
alias.variants.push([
|
|
10617
|
-
"sha256:" + (0,
|
|
12207
|
+
"sha256:" + (0, import_node_crypto12.createHash)("sha256").update(`${slug}:${alias.canonical}`, "utf8").digest("hex"),
|
|
10618
12208
|
standIn
|
|
10619
12209
|
]);
|
|
10620
12210
|
this.aliasDigests.add(standIn.toLowerCase());
|
|
@@ -11428,7 +13018,7 @@ function inputSchema(shorthand, position) {
|
|
|
11428
13018
|
`${position}.input: expected a table of field = "type"`
|
|
11429
13019
|
);
|
|
11430
13020
|
const properties = {};
|
|
11431
|
-
const
|
|
13021
|
+
const required2 = [];
|
|
11432
13022
|
for (const [name, raw] of Object.entries(shorthand)) {
|
|
11433
13023
|
if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(name))
|
|
11434
13024
|
throw new HookConfigError(
|
|
@@ -11462,9 +13052,9 @@ function inputSchema(shorthand, position) {
|
|
|
11462
13052
|
`${position}.input.${name}: expected "type" or a schema table`
|
|
11463
13053
|
);
|
|
11464
13054
|
properties[name] = schema;
|
|
11465
|
-
if (!optional)
|
|
13055
|
+
if (!optional) required2.push(name);
|
|
11466
13056
|
}
|
|
11467
|
-
return { type: "object", properties, required };
|
|
13057
|
+
return { type: "object", properties, required: required2 };
|
|
11468
13058
|
}
|
|
11469
13059
|
function placeholders(value) {
|
|
11470
13060
|
if (typeof value === "string")
|
|
@@ -13609,7 +15199,7 @@ var RedactionAudit = class _RedactionAudit {
|
|
|
13609
15199
|
};
|
|
13610
15200
|
|
|
13611
15201
|
// src/hooks/run.ts
|
|
13612
|
-
var
|
|
15202
|
+
var import_node_crypto13 = require("crypto");
|
|
13613
15203
|
var fs16 = __toESM(require("fs"));
|
|
13614
15204
|
var path14 = __toESM(require("path"));
|
|
13615
15205
|
var BLOCKING_EVENTS = [
|
|
@@ -13653,7 +15243,7 @@ var HookRun = class _HookRun {
|
|
|
13653
15243
|
source;
|
|
13654
15244
|
constructor(config, options) {
|
|
13655
15245
|
this.config = config;
|
|
13656
|
-
this.runId = options.runId ?? `run-${(0,
|
|
15246
|
+
this.runId = options.runId ?? `run-${(0, import_node_crypto13.randomBytes)(6).toString("hex")}`;
|
|
13657
15247
|
this.runKey = options.runKey ?? newRunKey();
|
|
13658
15248
|
this.alias = new AliasMap(this.runKey, options.slugs ?? config.aliasSlugs, {
|
|
13659
15249
|
publicLayerWins: config.aliasPublicLayerWins,
|
|
@@ -15615,7 +17205,7 @@ function editVerbSpecs() {
|
|
|
15615
17205
|
MESSAGE_FLAG,
|
|
15616
17206
|
{
|
|
15617
17207
|
name: "force",
|
|
15618
|
-
help: "
|
|
17208
|
+
help: "Also undo what reached main after it (later sessions, or writes outside sessions).",
|
|
15619
17209
|
boolean: true
|
|
15620
17210
|
},
|
|
15621
17211
|
HOST_FLAG
|
|
@@ -15668,7 +17258,7 @@ var CastRefusal = class extends CliError {
|
|
|
15668
17258
|
type;
|
|
15669
17259
|
};
|
|
15670
17260
|
var article = (type) => /^[aeiou]/i.test(type) ? "an" : "a";
|
|
15671
|
-
var
|
|
17261
|
+
var MEMBERS2 = /* @__PURE__ */ new Set([
|
|
15672
17262
|
"integer",
|
|
15673
17263
|
"number",
|
|
15674
17264
|
"boolean",
|
|
@@ -15687,7 +17277,7 @@ var BOOLEANS = {
|
|
|
15687
17277
|
};
|
|
15688
17278
|
function typeMembers(type) {
|
|
15689
17279
|
if (type === null) return [];
|
|
15690
|
-
return type.split("|").map((part) => part.trim().toLowerCase()).filter((part) =>
|
|
17280
|
+
return type.split("|").map((part) => part.trim().toLowerCase()).filter((part) => MEMBERS2.has(part));
|
|
15691
17281
|
}
|
|
15692
17282
|
function castAs(member, cell) {
|
|
15693
17283
|
const text2 = cell.trim();
|
|
@@ -15723,10 +17313,10 @@ function castJson(member, text2) {
|
|
|
15723
17313
|
return isObject(value) ? value : void 0;
|
|
15724
17314
|
}
|
|
15725
17315
|
var FieldCaster = class {
|
|
15726
|
-
constructor(name, type,
|
|
17316
|
+
constructor(name, type, required2) {
|
|
15727
17317
|
this.name = name;
|
|
15728
17318
|
this.type = type;
|
|
15729
|
-
this.required =
|
|
17319
|
+
this.required = required2;
|
|
15730
17320
|
this.members = typeMembers(type);
|
|
15731
17321
|
}
|
|
15732
17322
|
name;
|
|
@@ -16475,8 +18065,8 @@ function parseRows(paths, entity, options = {}) {
|
|
|
16475
18065
|
for (const path44 of paths) {
|
|
16476
18066
|
const text2 = readText(path44);
|
|
16477
18067
|
const parsed = isDelimitedName(path44) ? csvRowsIn(text2, path44, entity, options) : rowsIn(text2, path44, entity);
|
|
16478
|
-
for (const [name,
|
|
16479
|
-
(rows[name] ??= []).push(...
|
|
18068
|
+
for (const [name, listed2] of Object.entries(parsed)) {
|
|
18069
|
+
(rows[name] ??= []).push(...listed2);
|
|
16480
18070
|
}
|
|
16481
18071
|
}
|
|
16482
18072
|
return rows;
|
|
@@ -16524,12 +18114,12 @@ function rowsIn(text2, path44, entity) {
|
|
|
16524
18114
|
return jsonlRows2(stripped, path44, entity);
|
|
16525
18115
|
}
|
|
16526
18116
|
const out = {};
|
|
16527
|
-
for (const [name,
|
|
16528
|
-
if (!Array.isArray(
|
|
18117
|
+
for (const [name, listed2] of Object.entries(document)) {
|
|
18118
|
+
if (!Array.isArray(listed2))
|
|
16529
18119
|
throw refuse2(
|
|
16530
18120
|
`${path44}: ${name} must map to an array of rows (JSONL lines are {"entity", "row"})`
|
|
16531
18121
|
);
|
|
16532
|
-
out[name] =
|
|
18122
|
+
out[name] = listed2.map(
|
|
16533
18123
|
(row, index2) => rowObject2(row, `${path44}:${name}[${index2}]`)
|
|
16534
18124
|
);
|
|
16535
18125
|
}
|
|
@@ -16636,10 +18226,10 @@ var UNCOMMITTED_LISTED = 10;
|
|
|
16636
18226
|
function failOnUncommitted(sandboxId, error) {
|
|
16637
18227
|
const paths = uncommittedPaths(error);
|
|
16638
18228
|
if (paths === null) throw error;
|
|
16639
|
-
const
|
|
18229
|
+
const listed2 = paths.slice(0, UNCOMMITTED_LISTED);
|
|
16640
18230
|
const more = paths.length > UNCOMMITTED_LISTED ? ", \u2026" : "";
|
|
16641
18231
|
throw new CliError(
|
|
16642
|
-
`${paths.length} uncommitted file(s) (${
|
|
18232
|
+
`${paths.length} uncommitted file(s) (${listed2.join(", ")}${more}): commit them (gateway worlds sandbox commit ${sandboxId} -m "<why>") or discard them (gateway worlds sandbox close ${sandboxId} --force)`,
|
|
16643
18233
|
1
|
|
16644
18234
|
);
|
|
16645
18235
|
}
|
|
@@ -17867,16 +19457,16 @@ function registerBenchCommands(root) {
|
|
|
17867
19457
|
return 0;
|
|
17868
19458
|
}
|
|
17869
19459
|
const limit = arg.int(args, "limit");
|
|
17870
|
-
const
|
|
19460
|
+
const listed2 = await api(
|
|
17871
19461
|
creds,
|
|
17872
19462
|
"GET",
|
|
17873
19463
|
`/api/public/worlds/${encodeURIComponent(slug)}/tests${limit ? `?limit=${limit}` : ""}`
|
|
17874
19464
|
);
|
|
17875
|
-
if (!
|
|
19465
|
+
if (!listed2.runs.length)
|
|
17876
19466
|
ctx.stdout(
|
|
17877
19467
|
"no test runs yet \u2014 ship tests/ with the world and push, or `gateway worlds test <slug>`"
|
|
17878
19468
|
);
|
|
17879
|
-
for (const r of
|
|
19469
|
+
for (const r of listed2.runs) {
|
|
17880
19470
|
const s = r.summary;
|
|
17881
19471
|
ctx.stdout(
|
|
17882
19472
|
`${r.createdAt} ${r.state.padEnd(7)} ${r.trigger.padEnd(6)} ${r.versionId} ${s ? `${s.passed ?? 0} passed, ${s.failed ?? 0} failed` : r.error ?? ""} ${r.id}`
|
|
@@ -18120,7 +19710,7 @@ function importReport(dir, from) {
|
|
|
18120
19710
|
|
|
18121
19711
|
// src/benchmarks/container.ts
|
|
18122
19712
|
var import_node_child_process5 = require("child_process");
|
|
18123
|
-
var
|
|
19713
|
+
var import_node_crypto14 = require("crypto");
|
|
18124
19714
|
var fs28 = __toESM(require("fs"));
|
|
18125
19715
|
var os4 = __toESM(require("os"));
|
|
18126
19716
|
var path20 = __toESM(require("path"));
|
|
@@ -18503,7 +20093,7 @@ var DOCKER_SAFE = /^[A-Za-z0-9 ._-]*$/;
|
|
|
18503
20093
|
function dockerNameComponent(raw) {
|
|
18504
20094
|
const plain = raw.toLowerCase().replace(/[^a-z0-9._-]+/g, "-").replace(/[._-]{2,}/g, "-").replace(/^[._-]+|[._-]+$/g, "");
|
|
18505
20095
|
if (DOCKER_SAFE.test(raw)) return plain || "x";
|
|
18506
|
-
const digest2 = (0,
|
|
20096
|
+
const digest2 = (0, import_node_crypto14.createHash)("sha1").update(raw, "utf8").digest("hex").slice(0, 8);
|
|
18507
20097
|
return `${plain || "x"}-${digest2}`;
|
|
18508
20098
|
}
|
|
18509
20099
|
function dockerImageName(dirName, taskId) {
|
|
@@ -19073,17 +20663,17 @@ async function hostedDryRun(args, ctx, creds, pushDir) {
|
|
|
19073
20663
|
ctx,
|
|
19074
20664
|
pushDir
|
|
19075
20665
|
);
|
|
19076
|
-
const
|
|
19077
|
-
const task = pickTask(arg.str(args, "task"),
|
|
20666
|
+
const listed2 = await target.tasks(creds);
|
|
20667
|
+
const task = pickTask(arg.str(args, "task"), listed2.names, target.slug, ctx);
|
|
19078
20668
|
ctx.stderr(
|
|
19079
20669
|
`target ${target.slug}${target.ref ? `@${target.ref}` : ""} (${target.source}) \xB7 task ${task} \xB7 hosted, harbor oracle`
|
|
19080
20670
|
);
|
|
19081
|
-
const
|
|
20671
|
+
const client4 = new HostedDryRunClient(worldsOptions(creds));
|
|
19082
20672
|
const containerId = target.containerId ?? await resolveEnvironmentId(creds, target.slug);
|
|
19083
|
-
const dispatched = await
|
|
20673
|
+
const dispatched = await client4.dispatch({
|
|
19084
20674
|
containerId,
|
|
19085
20675
|
task,
|
|
19086
|
-
...
|
|
20676
|
+
...listed2.versionId ? { versionId: listed2.versionId } : {}
|
|
19087
20677
|
});
|
|
19088
20678
|
const json = arg.bool(args, "json");
|
|
19089
20679
|
if (arg.bool(args, "no-wait")) {
|
|
@@ -19092,7 +20682,7 @@ async function hostedDryRun(args, ctx, creds, pushDir) {
|
|
|
19092
20682
|
return 0;
|
|
19093
20683
|
}
|
|
19094
20684
|
const timeoutSeconds = arg.int(args, "wait-timeout") ?? 1200;
|
|
19095
|
-
const verdict = await
|
|
20685
|
+
const verdict = await client4.settle(dispatched.runId, {
|
|
19096
20686
|
timeoutSeconds,
|
|
19097
20687
|
onProgress: (v) => ctx.stderr(`# ${dispatched.task}: ${progressLine(v)}`)
|
|
19098
20688
|
});
|
|
@@ -19881,11 +21471,11 @@ function branchMoved(err) {
|
|
|
19881
21471
|
return err instanceof ApiError && err.status === 409 && /has moved/.test(err.message);
|
|
19882
21472
|
}
|
|
19883
21473
|
function refuseSlug(slug, existing, classified, incoming) {
|
|
19884
|
-
const
|
|
21474
|
+
const held2 = existing.shape ? STORED_SHAPE_LABELS[existing.shape] ?? existing.shape : existing.substrate;
|
|
19885
21475
|
const heldSide = existing.substrate === "world" ? "a world, hosted on the World Host" : "a container benchmark, executed by the benchmark runner";
|
|
19886
21476
|
const thisSide = incoming === "world" ? "a world for the World Host" : "a container benchmark for the benchmark runner";
|
|
19887
21477
|
throw new CliError(
|
|
19888
|
-
`benchmarks push: slug \`${slug}\` already holds a ${
|
|
21478
|
+
`benchmarks push: slug \`${slug}\` already holds a ${held2} \u2014 ${heldSide} \u2014 and this tree is a ${SHAPE_LABELS[classified.shape]}, ${thisSide}. A slug holds one substrate: pass --slug <new-slug>, or push a ${existing.substrate === "world" ? "world" : "container"} tree to add a version of \`${slug}\`. Nothing was written (the hub's versions door refuses the same push with benchmark_substrate_mismatch).`,
|
|
19889
21479
|
2
|
|
19890
21480
|
);
|
|
19891
21481
|
}
|
|
@@ -20432,9 +22022,9 @@ function iso(value) {
|
|
|
20432
22022
|
return text2.endsWith("Z") || text2.slice(10).includes("+") ? text2 : text2 + "Z";
|
|
20433
22023
|
}
|
|
20434
22024
|
function recordsFromClickhouse(document, where = "clickhouse") {
|
|
20435
|
-
const
|
|
20436
|
-
if (!Array.isArray(
|
|
20437
|
-
return
|
|
22025
|
+
const listed2 = isObject9(document) ? document.rows ?? document.results : document;
|
|
22026
|
+
if (!Array.isArray(listed2)) throw new CliError(`${where}: expected {rows|results: [...]} or a list of observations`, 1);
|
|
22027
|
+
return listed2.map((row, index2) => {
|
|
20438
22028
|
if (!isObject9(row)) throw new CliError(`${where}[${index2}] is not an object`, 1);
|
|
20439
22029
|
if (typeof row.name !== "string") throw new CliError(`${where}[${index2}] has no name; expected columns ${CLICKHOUSE_COLUMNS.join(", ")}`, 1);
|
|
20440
22030
|
const record = { tool: row.name, args: decoded(row.input, true), result: decoded(row.output, false) };
|
|
@@ -20496,21 +22086,21 @@ async function fetchSessionCalls(creds, sessionId) {
|
|
|
20496
22086
|
function recordsFromSessionCalls(calls, sessionId) {
|
|
20497
22087
|
const records2 = [];
|
|
20498
22088
|
const skipped = {};
|
|
20499
|
-
for (const
|
|
20500
|
-
if (
|
|
20501
|
-
const reason = `kind ${String(
|
|
22089
|
+
for (const call3 of calls) {
|
|
22090
|
+
if (call3.kind !== "call") {
|
|
22091
|
+
const reason = `kind ${String(call3.kind ?? "unknown")}`;
|
|
20502
22092
|
skipped[reason] = (skipped[reason] ?? 0) + 1;
|
|
20503
22093
|
continue;
|
|
20504
22094
|
}
|
|
20505
|
-
if (typeof
|
|
22095
|
+
if (typeof call3.tool !== "string" || !call3.tool) {
|
|
20506
22096
|
skipped["no tool"] = (skipped["no tool"] ?? 0) + 1;
|
|
20507
22097
|
continue;
|
|
20508
22098
|
}
|
|
20509
|
-
const record = { tool:
|
|
20510
|
-
if (
|
|
20511
|
-
else record.result =
|
|
20512
|
-
if (typeof
|
|
20513
|
-
record.source = `session:${sessionId}/${String(
|
|
22099
|
+
const record = { tool: call3.tool, args: isObject9(call3.args) ? call3.args : {}, session: sessionId };
|
|
22100
|
+
if (call3.error !== void 0 && call3.error !== null && call3.error !== "") record.error = String(call3.error);
|
|
22101
|
+
else record.result = call3.result;
|
|
22102
|
+
if (typeof call3.completedAt === "string") record.at = call3.completedAt;
|
|
22103
|
+
record.source = `session:${sessionId}/${String(call3.seq ?? "?")}`;
|
|
20514
22104
|
records2.push(record);
|
|
20515
22105
|
}
|
|
20516
22106
|
return { records: records2, skipped };
|
|
@@ -20529,7 +22119,7 @@ async function extractRows(input, config, opts, out) {
|
|
|
20529
22119
|
if (!entity) throw new CliError(`Unknown entity ${opts.entity}; the world has ${Object.keys(config.entities).sort().join(", ")}`, 1);
|
|
20530
22120
|
const keys = entity.primaryKey;
|
|
20531
22121
|
const summary2 = { read: 0, rows: 0, unknownFields: {}, redacted: { dropped: 0, hashed: 0 } };
|
|
20532
|
-
const
|
|
22122
|
+
const held2 = /* @__PURE__ */ new Map();
|
|
20533
22123
|
const skipped = {};
|
|
20534
22124
|
const skip = (reason) => {
|
|
20535
22125
|
skipped[reason] = (skipped[reason] ?? 0) + 1;
|
|
@@ -20539,16 +22129,16 @@ async function extractRows(input, config, opts, out) {
|
|
|
20539
22129
|
const row = clean(raw, entity.fields, summary2);
|
|
20540
22130
|
if (!keys.every((name) => row.has(name))) return skip(`row lacks the primary key (${keys.join(", ")})`);
|
|
20541
22131
|
const key2 = dumps(keys.map((name) => row.get(name)));
|
|
20542
|
-
const existing =
|
|
20543
|
-
if (!existing)
|
|
20544
|
-
else if (opts.merge === "upsert")
|
|
22132
|
+
const existing = held2.get(key2);
|
|
22133
|
+
if (!existing) held2.set(key2, row);
|
|
22134
|
+
else if (opts.merge === "upsert") held2.set(key2, row);
|
|
20545
22135
|
else for (const [name, value] of row) if (!existing.has(name)) existing.set(name, value);
|
|
20546
22136
|
};
|
|
20547
22137
|
await adapters[opts.shape](input, config, keys, take, skip);
|
|
20548
22138
|
if (Object.keys(skipped).length) summary2.skipped = skipped;
|
|
20549
22139
|
if (summary2.read === 0 && Object.keys(skipped).length) summary2.hint = SHAPE_HINT[opts.shape];
|
|
20550
22140
|
const policy = opts.redact ? config.redact : null;
|
|
20551
|
-
for (const row of
|
|
22141
|
+
for (const row of held2.values()) {
|
|
20552
22142
|
let final = row;
|
|
20553
22143
|
if (policy) {
|
|
20554
22144
|
final = redact(row, policy, config.slug ?? "");
|
|
@@ -20597,9 +22187,9 @@ var toolResults = async (input, _config, keys, take, skip) => {
|
|
|
20597
22187
|
skip("record has no raw_output object");
|
|
20598
22188
|
continue;
|
|
20599
22189
|
}
|
|
20600
|
-
let
|
|
20601
|
-
if (
|
|
20602
|
-
const items = objects(
|
|
22190
|
+
let listed2 = raw.get("results");
|
|
22191
|
+
if (listed2 === void 0 || listed2 === null) listed2 = raw.get("items");
|
|
22192
|
+
const items = objects(listed2);
|
|
20603
22193
|
if (items.length === 0) skip("raw_output has no results[] or items[]");
|
|
20604
22194
|
for (const item of items) {
|
|
20605
22195
|
if (keys.every((name) => item.has(name))) take(item);
|
|
@@ -20831,10 +22421,10 @@ function skeleton(records2, entities, kind, opts = {}) {
|
|
|
20831
22421
|
const shapeNames = Object.keys(group.shapes);
|
|
20832
22422
|
if (kind === "tool-call" && shapeNames.length && shapeNames.every((shape) => shape === "an array of objects")) select = "result[*]";
|
|
20833
22423
|
else if (kind === "tool-call" && shapeNames.length && shapeNames.every((shape) => shape === "an object")) {
|
|
20834
|
-
const
|
|
20835
|
-
if (
|
|
20836
|
-
select = `result.${
|
|
20837
|
-
lines.push(`# result.${
|
|
22424
|
+
const listed2 = Object.entries(group.fields).filter(([, info]) => info.list && Object.keys(info.nested).length).map(([name2]) => name2);
|
|
22425
|
+
if (listed2.length === 1) {
|
|
22426
|
+
select = `result.${listed2[0]}[*]`;
|
|
22427
|
+
lines.push(`# result.${listed2[0]} holds the rows: [*] selects each item of an array`);
|
|
20838
22428
|
}
|
|
20839
22429
|
}
|
|
20840
22430
|
lines.push("[[sources]]", `name = "${name}"`, `kind = "${kind}"`, `select = "${select}"`);
|
|
@@ -21204,7 +22794,7 @@ var TreeImport = class _TreeImport {
|
|
|
21204
22794
|
);
|
|
21205
22795
|
if (!dryRun) await this.refuseOverInlineCap(paths);
|
|
21206
22796
|
const rows = parseRows(paths, this.entity);
|
|
21207
|
-
const count = Object.values(rows).reduce((n,
|
|
22797
|
+
const count = Object.values(rows).reduce((n, listed2) => n + listed2.length, 0);
|
|
21208
22798
|
const { importLocalWorldData: importLocalWorldData2, checkLocalWorldData: checkLocalWorldData2 } = await runtimeData();
|
|
21209
22799
|
const { credentialsForRuntime: credentialsForRuntime2 } = await runtimeLocal();
|
|
21210
22800
|
const creds = credentialsForRuntime2(void 0);
|
|
@@ -21375,9 +22965,9 @@ async function rowsOrRefuse(source2, files) {
|
|
|
21375
22965
|
yield* source2;
|
|
21376
22966
|
})();
|
|
21377
22967
|
}
|
|
21378
|
-
async function stageDriveChunks(
|
|
22968
|
+
async function stageDriveChunks(client4, batchId, drive, entity, manifest, progress) {
|
|
21379
22969
|
for (const [ordinal, path44] of drive.entries()) {
|
|
21380
|
-
const entry = await
|
|
22970
|
+
const entry = await client4.stageDrive(batchId, { ordinal, path: path44, entity });
|
|
21381
22971
|
recordChunk(manifest, entry);
|
|
21382
22972
|
writeManifest(manifest);
|
|
21383
22973
|
progress(
|
|
@@ -22045,8 +23635,8 @@ function parseWhere(clauses) {
|
|
|
22045
23635
|
if (!field2)
|
|
22046
23636
|
throw new CliError(`--where takes field=value, got '${clause}'`);
|
|
22047
23637
|
const value = clause.slice(eq + 1);
|
|
22048
|
-
const
|
|
22049
|
-
where[field2] =
|
|
23638
|
+
const held2 = where[field2];
|
|
23639
|
+
where[field2] = held2 === void 0 ? value : [...Array.isArray(held2) ? held2 : [held2], value];
|
|
22050
23640
|
}
|
|
22051
23641
|
return where;
|
|
22052
23642
|
}
|
|
@@ -22138,7 +23728,7 @@ async function importBatch(world, files, args, ctx, purpose, onStatus, labels =
|
|
|
22138
23728
|
const named2 = inputLabels(files, labels);
|
|
22139
23729
|
const creds = credentials(args);
|
|
22140
23730
|
const flags = importFlags(args, purpose);
|
|
22141
|
-
const
|
|
23731
|
+
const client4 = new WorldDataApi(creds, slug);
|
|
22142
23732
|
const progress = (line) => {
|
|
22143
23733
|
if (showProgress()) ctx.stderr(line);
|
|
22144
23734
|
};
|
|
@@ -22170,7 +23760,7 @@ async function importBatch(world, files, args, ctx, purpose, onStatus, labels =
|
|
|
22170
23760
|
);
|
|
22171
23761
|
let manifest;
|
|
22172
23762
|
if (resumable) {
|
|
22173
|
-
const status2 = await
|
|
23763
|
+
const status2 = await client4.get(resumable.batchId);
|
|
22174
23764
|
if (status2.state !== "open" && status2.state !== "uploading")
|
|
22175
23765
|
throw new CliError(
|
|
22176
23766
|
`batch ${resumable.batchId} is ${status2.state}; only an open or uploading batch resumes`,
|
|
@@ -22181,7 +23771,7 @@ async function importBatch(world, files, args, ctx, purpose, onStatus, labels =
|
|
|
22181
23771
|
`resuming batch ${manifest.batchId} (${manifest.chunks.length} chunks recorded)`
|
|
22182
23772
|
);
|
|
22183
23773
|
} else {
|
|
22184
|
-
const opened = await
|
|
23774
|
+
const opened = await client4.open({
|
|
22185
23775
|
mode: plan.mode,
|
|
22186
23776
|
merge: plan.merge,
|
|
22187
23777
|
...plan.redact && plan.redact !== "off" ? { redact: plan.redact } : {},
|
|
@@ -22213,7 +23803,7 @@ async function importBatch(world, files, args, ctx, purpose, onStatus, labels =
|
|
|
22213
23803
|
}
|
|
22214
23804
|
const batchId = manifest.batchId;
|
|
22215
23805
|
const staged = await stageDriveChunks(
|
|
22216
|
-
|
|
23806
|
+
client4,
|
|
22217
23807
|
batchId,
|
|
22218
23808
|
drive,
|
|
22219
23809
|
plan.entity,
|
|
@@ -22234,14 +23824,14 @@ async function importBatch(world, files, args, ctx, purpose, onStatus, labels =
|
|
|
22234
23824
|
progress(`chunk ${chunk.ordinal}: already uploaded (${chunk.rows} rows)`);
|
|
22235
23825
|
return;
|
|
22236
23826
|
}
|
|
22237
|
-
const entry = await
|
|
23827
|
+
const entry = await client4.upload(batchId, chunk);
|
|
22238
23828
|
recordChunk(manifest, entry);
|
|
22239
23829
|
writeManifest(manifest);
|
|
22240
23830
|
progress(
|
|
22241
23831
|
`chunk ${chunk.ordinal}: uploaded ${chunk.rows} rows, ${chunk.bytes} bytes (${entry.chunkId})`
|
|
22242
23832
|
);
|
|
22243
23833
|
});
|
|
22244
|
-
await
|
|
23834
|
+
await client4.complete(batchId);
|
|
22245
23835
|
manifest.completed = true;
|
|
22246
23836
|
writeManifest(manifest);
|
|
22247
23837
|
progress(`batch ${batchId} complete: ${manifest.chunks.length} chunks`);
|
|
@@ -22250,7 +23840,7 @@ async function importBatch(world, files, args, ctx, purpose, onStatus, labels =
|
|
|
22250
23840
|
else ctx.stdout(JSON.stringify({ batchId, state: "queued" }));
|
|
22251
23841
|
return 0;
|
|
22252
23842
|
}
|
|
22253
|
-
const status = await waitForBatch(
|
|
23843
|
+
const status = await waitForBatch(client4, batchId, {
|
|
22254
23844
|
onPhase: (line) => progress(line),
|
|
22255
23845
|
initialDelayMs: pollMs2()
|
|
22256
23846
|
});
|
|
@@ -22618,9 +24208,9 @@ async function ingestCommand(world, inputs, args, ctx, labels = {}) {
|
|
|
22618
24208
|
skipped: {},
|
|
22619
24209
|
refusals: [],
|
|
22620
24210
|
rows: Object.fromEntries(
|
|
22621
|
-
Object.entries(projected).map(([entity,
|
|
24211
|
+
Object.entries(projected).map(([entity, listed2]) => [
|
|
22622
24212
|
entity,
|
|
22623
|
-
|
|
24213
|
+
listed2.length
|
|
22624
24214
|
])
|
|
22625
24215
|
),
|
|
22626
24216
|
dryRun,
|
|
@@ -22789,8 +24379,8 @@ function readDatasetItems(file) {
|
|
|
22789
24379
|
if (Array.isArray(data)) return data;
|
|
22790
24380
|
if (data && typeof data === "object") {
|
|
22791
24381
|
const record = data;
|
|
22792
|
-
const
|
|
22793
|
-
return Array.isArray(
|
|
24382
|
+
const listed2 = record.tasks ?? record.items;
|
|
24383
|
+
return Array.isArray(listed2) ? listed2 : [];
|
|
22794
24384
|
}
|
|
22795
24385
|
return [];
|
|
22796
24386
|
}
|
|
@@ -22827,11 +24417,11 @@ function registerDatasetCommands(root) {
|
|
|
22827
24417
|
const creds = credentials(args);
|
|
22828
24418
|
const agent = arg.str(args, "agent");
|
|
22829
24419
|
if (agent) {
|
|
22830
|
-
const
|
|
22831
|
-
if (!
|
|
22832
|
-
ctx.stderr(`Warning: Could not fetch agents for validation: HTTP ${
|
|
24420
|
+
const listed2 = await rawRequest(creds, "GET", "/api/public/agents");
|
|
24421
|
+
if (!listed2.ok) {
|
|
24422
|
+
ctx.stderr(`Warning: Could not fetch agents for validation: HTTP ${listed2.status}`);
|
|
22833
24423
|
} else {
|
|
22834
|
-
const agents = (
|
|
24424
|
+
const agents = (listed2.json().agents ?? []).filter((a) => a.name === agent);
|
|
22835
24425
|
if (agents.length === 0) ctx.stderr(`Warning: Agent '${agent}' not found, skipping validation`);
|
|
22836
24426
|
else if (!agents[0].taskInputSchema)
|
|
22837
24427
|
ctx.stdout(`Agent '${agent}' has no taskInputSchema, skipping validation`);
|
|
@@ -23476,14 +25066,14 @@ function registerSecretCommands(root) {
|
|
|
23476
25066
|
}
|
|
23477
25067
|
|
|
23478
25068
|
// src/cli/platform/session.ts
|
|
23479
|
-
var
|
|
25069
|
+
var fs49 = __toESM(require("fs"));
|
|
23480
25070
|
init_config();
|
|
23481
25071
|
init_router();
|
|
23482
25072
|
init_worlds();
|
|
23483
25073
|
init_shared();
|
|
23484
25074
|
|
|
23485
25075
|
// src/cli/platform/task.ts
|
|
23486
|
-
var
|
|
25076
|
+
var fs48 = __toESM(require("fs"));
|
|
23487
25077
|
var path37 = __toESM(require("path"));
|
|
23488
25078
|
var import_node_url3 = require("url");
|
|
23489
25079
|
init_config();
|
|
@@ -23496,7 +25086,7 @@ var import_node_url2 = require("url");
|
|
|
23496
25086
|
init_router();
|
|
23497
25087
|
init_config();
|
|
23498
25088
|
init_worlds();
|
|
23499
|
-
|
|
25089
|
+
init_session2();
|
|
23500
25090
|
init_hub();
|
|
23501
25091
|
init_validate();
|
|
23502
25092
|
init_client();
|
|
@@ -23970,30 +25560,11 @@ function registerRunCommands2(worlds) {
|
|
|
23970
25560
|
// src/cli/platform/task.ts
|
|
23971
25561
|
init_worlds();
|
|
23972
25562
|
init_shared();
|
|
23973
|
-
|
|
23974
|
-
|
|
23975
|
-
|
|
23976
|
-
|
|
23977
|
-
|
|
23978
|
-
if (page >= batch.meta.totalPages) return null;
|
|
23979
|
-
}
|
|
23980
|
-
}
|
|
23981
|
-
var WORLD_FLAG = {
|
|
23982
|
-
name: "world",
|
|
23983
|
-
short: "w",
|
|
23984
|
-
help: "Pin the task to this world (slug); validated against its contract."
|
|
23985
|
-
};
|
|
23986
|
-
var NO_WORLD_FLAG = {
|
|
23987
|
-
name: "no-world",
|
|
23988
|
-
help: "Unpin the task so it can open on any world.",
|
|
23989
|
-
boolean: true
|
|
23990
|
-
};
|
|
23991
|
-
var MESSAGE_FLAG3 = {
|
|
23992
|
-
name: "message",
|
|
23993
|
-
short: "m",
|
|
23994
|
-
help: "Note kept with this version."
|
|
23995
|
-
};
|
|
23996
|
-
var TASK_SPEC_HELP = 'A task spec is JSON:\n {"instruction": "<what the agent is told>",\n "name": "<optional>",\n "seed": {"mode": "append|replace", "rows": {"<entity>": [{...row}, ...]}}, # rows go UNDER seed.rows\n "grader": {"kind": "assertions", "checks": [{"entity": "<entity>", "where": {"<field>": <scalar>},\n "assert": "exists|absent|count|all|any",\n "count": {"eq"|"gte"|"lte": <n>}, # assert: count\n "field": "<field>", "op": "eq|neq|in|gt|gte|lt|lte|contains", "value": <scalar>}]} # assert: all|any\n | {"kind": "python", "source": "<verify.py body>", "timeoutSeconds"?: <n>}\n | {"kind": "rubric", "rubric": "<what the judge looks for>", "criteria"?: [{"id", "description", "weight"?}]},\n "tools": ["<tool>", ...], # optional allow-list\n "metadata": {...}, # optional, echoed back\n "worlds": {"<alias>": {"slug": "<world>", "ref"?: "<branch|tag|version id>", "seed"?, "grader"?, "tools"?}}} # multi-world: one session per alias\nWithout seed the session starts on the version\'s base data; without grader `grade` answers reward: null.\nWith worlds, seed/grader/tools live under each alias (not at the top level) and `worlds task up` opens the sessions.';
|
|
25563
|
+
|
|
25564
|
+
// src/cli/platform/taskSpec.ts
|
|
25565
|
+
var fs47 = __toESM(require("fs"));
|
|
25566
|
+
init_router();
|
|
25567
|
+
var TASK_SPEC_HELP = 'A task spec is JSON:\n {"instruction": "<what the agent is told>",\n "name": "<optional>",\n "seed": {"mode": "append|replace", "rows": {"<entity>": [{...row}, ...]}}, # rows go UNDER seed.rows\n "grader": {"kind": "assertions", "checks": [{"entity": "<entity>", "where": {"<field>": <scalar>},\n "assert": "exists|absent|count|all|any",\n "count": {"eq"|"gte"|"lte": <n>}, # assert: count\n "field": "<field>", "op": "eq|neq|in|gt|gte|lt|lte|contains", "value": <scalar>}]} # assert: all|any\n | {"kind": "python", "source": "<verify.py body>", "timeoutSeconds"?: <n>}\n | {"kind": "rubric", "rubric": "<what the judge looks for>", "criteria"?: [{"id", "description", "weight"?}]},\n "tools": ["<tool>", ...], # optional allow-list\n "metadata": {...}, # optional, echoed back\n "worlds": {"<alias>": {"slug": "<world>", "ref"?: "<branch|tag|version id>", "seed"?, "grader"?, "tools"?}}, # multi-world: one session per alias\n "verifiers": [{"name": "<name>", "scope": ["<alias>", "<alias>", ...], "kind": "assertions|python", "checks"|"source": ...}]} # cross-world: entities as <alias>.<entity>, call logs as <alias>.calls\nWithout seed the session starts on the version\'s base data; without grader `grade` answers reward: null.\nWith worlds, seed/grader/tools live under each alias (not at the top level) and `worlds task up` opens the sessions.\nWithout worlds, a verifier runs on the session named by its first scope alias, so "name" must be that alias.';
|
|
23997
25568
|
var SPEC_KEYS = /* @__PURE__ */ new Set([
|
|
23998
25569
|
"name",
|
|
23999
25570
|
"instruction",
|
|
@@ -24001,13 +25572,18 @@ var SPEC_KEYS = /* @__PURE__ */ new Set([
|
|
|
24001
25572
|
"grader",
|
|
24002
25573
|
"tools",
|
|
24003
25574
|
"metadata",
|
|
24004
|
-
"worlds"
|
|
25575
|
+
"worlds",
|
|
25576
|
+
"verifiers"
|
|
24005
25577
|
]);
|
|
24006
25578
|
var WORLD_KEYS = /* @__PURE__ */ new Set(["slug", "ref", "seed", "grader", "tools"]);
|
|
24007
25579
|
var SEED_KEYS = /* @__PURE__ */ new Set(["mode", "redact", "rows"]);
|
|
24008
25580
|
var SEED_MODES = /* @__PURE__ */ new Set(["append", "replace"]);
|
|
24009
25581
|
var SEED_REDACT = /* @__PURE__ */ new Set(["off", "apply", "refuse"]);
|
|
24010
25582
|
var GRADER_KINDS = /* @__PURE__ */ new Set(["assertions", "python", "rubric"]);
|
|
25583
|
+
var VERIFIER_KEYS = /* @__PURE__ */ new Map([
|
|
25584
|
+
["assertions", /* @__PURE__ */ new Set(["name", "scope", "kind", "checks"])],
|
|
25585
|
+
["python", /* @__PURE__ */ new Set(["name", "scope", "kind", "source", "timeoutSeconds"])]
|
|
25586
|
+
]);
|
|
24011
25587
|
var CHECK_KEYS = /* @__PURE__ */ new Set([
|
|
24012
25588
|
"id",
|
|
24013
25589
|
"weight",
|
|
@@ -24031,134 +25607,241 @@ var FIELD_OPS = /* @__PURE__ */ new Set([
|
|
|
24031
25607
|
"contains"
|
|
24032
25608
|
]);
|
|
24033
25609
|
var isRecord = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
|
|
24034
|
-
|
|
24035
|
-
|
|
24036
|
-
|
|
24037
|
-
|
|
24038
|
-
|
|
24039
|
-
|
|
24040
|
-
|
|
24041
|
-
|
|
24042
|
-
|
|
24043
|
-
|
|
24044
|
-
|
|
24045
|
-
|
|
24046
|
-
|
|
24047
|
-
|
|
24048
|
-
|
|
24049
|
-
|
|
25610
|
+
var isStringList = (value) => Array.isArray(value) && value.every((item) => typeof item === "string");
|
|
25611
|
+
var oneOf = (set, value) => typeof value === "string" && set.has(value);
|
|
25612
|
+
var listed = (set) => [...set].join(", ");
|
|
25613
|
+
var repeatedAt = (items, i) => items.indexOf(items[i]) < i;
|
|
25614
|
+
var checkKey = (check, i) => {
|
|
25615
|
+
if (!isRecord(check)) return void 0;
|
|
25616
|
+
return typeof check.id === "string" ? check.id : `check_${i}`;
|
|
25617
|
+
};
|
|
25618
|
+
var keyCollision = (check, i) => typeof check.id === "string" ? `check id '${check.id}' is used twice (an id of the form check_<n> is also the positional key of check n)` : `check ${i} has no id and its positional key 'check_${i}' is taken by another check's id`;
|
|
25619
|
+
var TaskSpecCheck = class {
|
|
25620
|
+
constructor(spec) {
|
|
25621
|
+
this.spec = spec;
|
|
25622
|
+
}
|
|
25623
|
+
spec;
|
|
25624
|
+
issues = [];
|
|
25625
|
+
run() {
|
|
25626
|
+
const spec = this.spec;
|
|
25627
|
+
for (const key2 of Object.keys(spec).filter((k) => !SPEC_KEYS.has(k)))
|
|
25628
|
+
this.issue(`unknown key "${key2}" (a spec has ${listed(SPEC_KEYS)})`);
|
|
25629
|
+
if (spec.name !== void 0 && typeof spec.name !== "string")
|
|
25630
|
+
this.issue("name is a string");
|
|
25631
|
+
if (spec.metadata !== void 0 && !isRecord(spec.metadata))
|
|
25632
|
+
this.issue("metadata is a JSON object");
|
|
25633
|
+
this.tools(spec.tools, "tools");
|
|
25634
|
+
this.seed(spec.seed, "seed");
|
|
25635
|
+
this.grader(spec.grader, "grader");
|
|
25636
|
+
this.verifiers(spec.verifiers);
|
|
25637
|
+
this.worlds(spec.worlds);
|
|
25638
|
+
return this.issues;
|
|
25639
|
+
}
|
|
25640
|
+
issue(message) {
|
|
25641
|
+
this.issues.push(message);
|
|
25642
|
+
}
|
|
25643
|
+
worlds(worlds) {
|
|
25644
|
+
if (worlds === void 0) return;
|
|
24050
25645
|
for (const key2 of ["seed", "grader", "tools"])
|
|
24051
|
-
if (spec[key2] !== void 0)
|
|
24052
|
-
|
|
25646
|
+
if (this.spec[key2] !== void 0)
|
|
25647
|
+
this.issue(
|
|
24053
25648
|
`a task with worlds carries ${key2} per world (worlds.<alias>.${key2}), not at the top level`
|
|
24054
25649
|
);
|
|
24055
25650
|
if (!isRecord(worlds) || !Object.keys(worlds).length)
|
|
24056
|
-
|
|
25651
|
+
return this.issue(
|
|
24057
25652
|
'worlds is {"<alias>": {"slug": "<world>", "ref"?, "seed"?, "grader"?, "tools"?}} with at least one alias'
|
|
24058
25653
|
);
|
|
24059
|
-
|
|
24060
|
-
|
|
24061
|
-
|
|
24062
|
-
|
|
24063
|
-
|
|
24064
|
-
|
|
24065
|
-
}
|
|
24066
|
-
|
|
24067
|
-
|
|
24068
|
-
|
|
24069
|
-
|
|
24070
|
-
|
|
24071
|
-
|
|
24072
|
-
|
|
24073
|
-
|
|
24074
|
-
|
|
24075
|
-
|
|
24076
|
-
|
|
24077
|
-
|
|
24078
|
-
|
|
24079
|
-
|
|
24080
|
-
|
|
24081
|
-
|
|
24082
|
-
|
|
24083
|
-
|
|
24084
|
-
|
|
24085
|
-
|
|
24086
|
-
|
|
24087
|
-
|
|
24088
|
-
|
|
24089
|
-
|
|
24090
|
-
|
|
24091
|
-
|
|
24092
|
-
|
|
24093
|
-
|
|
24094
|
-
|
|
25654
|
+
for (const [alias, world] of Object.entries(worlds))
|
|
25655
|
+
this.world(world, `worlds.${alias}`);
|
|
25656
|
+
}
|
|
25657
|
+
world(world, at) {
|
|
25658
|
+
if (!isRecord(world))
|
|
25659
|
+
return this.issue(
|
|
25660
|
+
`${at} is an object {slug, ref?, seed?, grader?, tools?}`
|
|
25661
|
+
);
|
|
25662
|
+
for (const k of Object.keys(world).filter((k2) => !WORLD_KEYS.has(k2)))
|
|
25663
|
+
this.issue(`${at}.${k} is not a world key (${listed(WORLD_KEYS)})`);
|
|
25664
|
+
if (typeof world.slug !== "string" || !world.slug)
|
|
25665
|
+
this.issue(`${at}.slug names the hosted world the alias opens`);
|
|
25666
|
+
if (world.ref !== void 0 && typeof world.ref !== "string")
|
|
25667
|
+
this.issue(`${at}.ref is a branch, tag or version id`);
|
|
25668
|
+
this.tools(world.tools, `${at}.tools`);
|
|
25669
|
+
this.seed(world.seed, `${at}.seed`);
|
|
25670
|
+
this.grader(world.grader, `${at}.grader`);
|
|
25671
|
+
}
|
|
25672
|
+
tools(tools, at) {
|
|
25673
|
+
if (tools !== void 0 && !isStringList(tools))
|
|
25674
|
+
this.issue(`${at} is a list of tool names`);
|
|
25675
|
+
}
|
|
25676
|
+
seed(seed, at) {
|
|
25677
|
+
if (seed === void 0) return;
|
|
25678
|
+
if (!isRecord(seed)) return this.issue(`${at} is an object {mode?, rows}`);
|
|
25679
|
+
this.seedRows(seed, at);
|
|
25680
|
+
if (seed.mode !== void 0 && !oneOf(SEED_MODES, seed.mode))
|
|
25681
|
+
this.issue(
|
|
25682
|
+
`${at}.mode is append or replace, got ${JSON.stringify(seed.mode)}`
|
|
25683
|
+
);
|
|
25684
|
+
if (seed.redact !== void 0 && !oneOf(SEED_REDACT, seed.redact))
|
|
25685
|
+
this.issue(
|
|
25686
|
+
`${at}.redact is off, apply or refuse, got ${JSON.stringify(seed.redact)}`
|
|
25687
|
+
);
|
|
25688
|
+
}
|
|
25689
|
+
seedRows(seed, at) {
|
|
25690
|
+
const strays = Object.keys(seed).filter((k) => !SEED_KEYS.has(k));
|
|
25691
|
+
if (seed.rows === void 0 && strays.length)
|
|
25692
|
+
return this.issue(
|
|
25693
|
+
`${at}.rows is missing \u2014 rows go under ${at}.rows, not ${at}.${strays[0]}: {"seed": {"rows": {${strays.map((k) => `"${k}": [...]`).join(", ")}}}}`
|
|
25694
|
+
);
|
|
24095
25695
|
for (const k of strays)
|
|
24096
|
-
|
|
24097
|
-
if (!isRecord(seed.rows))
|
|
24098
|
-
|
|
24099
|
-
|
|
24100
|
-
|
|
24101
|
-
|
|
25696
|
+
this.issue(`${at}.${k} is not a seed key (seed has mode, redact, rows)`);
|
|
25697
|
+
if (!isRecord(seed.rows))
|
|
25698
|
+
return this.issue(`${at}.rows is {"<entity>": [row, ...]}`);
|
|
25699
|
+
for (const [entity, rows] of Object.entries(seed.rows))
|
|
25700
|
+
if (!Array.isArray(rows) || !rows.every(isRecord))
|
|
25701
|
+
this.issue(`${at}.rows.${entity} is a list of row objects`);
|
|
25702
|
+
}
|
|
25703
|
+
grader(grader, at) {
|
|
25704
|
+
if (grader === void 0) return;
|
|
25705
|
+
if (!isRecord(grader)) return this.issue(`${at} is an object {kind, ...}`);
|
|
25706
|
+
if (!oneOf(GRADER_KINDS, grader.kind))
|
|
25707
|
+
return this.issue(
|
|
25708
|
+
`${at}.kind is one of assertions, python, rubric, got ${JSON.stringify(grader.kind)}` + (grader.checks !== void 0 ? ' (checks go with kind: "assertions")' : "")
|
|
25709
|
+
);
|
|
25710
|
+
this.graderBodies[grader.kind](grader, at);
|
|
24102
25711
|
}
|
|
24103
|
-
|
|
24104
|
-
|
|
24105
|
-
|
|
24106
|
-
|
|
24107
|
-
|
|
24108
|
-
|
|
24109
|
-
|
|
24110
|
-
|
|
24111
|
-
|
|
24112
|
-
|
|
24113
|
-
|
|
24114
|
-
|
|
24115
|
-
|
|
24116
|
-
|
|
24117
|
-
`${at}.kind is one of assertions, python, rubric, got ${JSON.stringify(grader.kind)}` + (grader.checks !== void 0 ? ' (checks go with kind: "assertions")' : "")
|
|
24118
|
-
);
|
|
24119
|
-
if (grader.kind === "assertions") {
|
|
24120
|
-
const checks = grader.checks;
|
|
25712
|
+
graderBodies = {
|
|
25713
|
+
assertions: (grader, at) => this.checks(grader.checks, at),
|
|
25714
|
+
python: (grader, at) => {
|
|
25715
|
+
if (typeof grader.source !== "string" || !grader.source)
|
|
25716
|
+
this.issue(`${at}.source is the verify.py body (kind: "python")`);
|
|
25717
|
+
},
|
|
25718
|
+
rubric: (grader, at) => {
|
|
25719
|
+
if (typeof grader.rubric !== "string" || !grader.rubric)
|
|
25720
|
+
this.issue(
|
|
25721
|
+
`${at}.rubric is what the judge is told to look for (kind: "rubric")`
|
|
25722
|
+
);
|
|
25723
|
+
}
|
|
25724
|
+
};
|
|
25725
|
+
checks(checks, at) {
|
|
24121
25726
|
if (!Array.isArray(checks) || !checks.length)
|
|
24122
|
-
return
|
|
24123
|
-
checks.
|
|
24124
|
-
|
|
24125
|
-
|
|
24126
|
-
|
|
24127
|
-
|
|
24128
|
-
|
|
24129
|
-
|
|
24130
|
-
|
|
24131
|
-
|
|
24132
|
-
|
|
24133
|
-
|
|
24134
|
-
|
|
24135
|
-
|
|
24136
|
-
|
|
24137
|
-
|
|
24138
|
-
|
|
24139
|
-
|
|
24140
|
-
|
|
24141
|
-
|
|
24142
|
-
|
|
24143
|
-
|
|
24144
|
-
|
|
24145
|
-
`${at}
|
|
24146
|
-
)
|
|
24147
|
-
|
|
24148
|
-
|
|
24149
|
-
|
|
24150
|
-
|
|
24151
|
-
|
|
24152
|
-
|
|
24153
|
-
|
|
24154
|
-
|
|
24155
|
-
|
|
24156
|
-
|
|
24157
|
-
|
|
24158
|
-
|
|
24159
|
-
|
|
24160
|
-
|
|
25727
|
+
return this.issue(`${at}.checks is a non-empty list of checks`);
|
|
25728
|
+
const keys = checks.map((check, i) => checkKey(check, i));
|
|
25729
|
+
checks.forEach((check, i) => {
|
|
25730
|
+
if (keys[i] !== void 0 && repeatedAt(keys, i))
|
|
25731
|
+
this.issue(`${at}.checks[${i}]: ${keyCollision(check, i)}`);
|
|
25732
|
+
this.check(check, `${at}.checks[${i}]`);
|
|
25733
|
+
});
|
|
25734
|
+
}
|
|
25735
|
+
check(check, at) {
|
|
25736
|
+
if (!isRecord(check))
|
|
25737
|
+
return this.issue(`${at} is an object {entity, where?, assert?, ...}`);
|
|
25738
|
+
for (const k of Object.keys(check).filter((k2) => !CHECK_KEYS.has(k2)))
|
|
25739
|
+
this.issue(`${at}.${k} is not a check key (${listed(CHECK_KEYS)})`);
|
|
25740
|
+
if (typeof check.entity !== "string" || !check.entity)
|
|
25741
|
+
this.issue(`${at}.entity names the entity the check selects rows of`);
|
|
25742
|
+
if (check.where !== void 0 && !isRecord(check.where))
|
|
25743
|
+
this.issue(`${at}.where is {"<field>": <scalar>}`);
|
|
25744
|
+
const assert = check.assert ?? "exists";
|
|
25745
|
+
if (!oneOf(ASSERTIONS, assert))
|
|
25746
|
+
return this.issue(
|
|
25747
|
+
`${at}.assert is one of exists, absent, count, all, any, got ${JSON.stringify(assert)}`
|
|
25748
|
+
);
|
|
25749
|
+
if (assert === "count" && !isRecord(check.count))
|
|
25750
|
+
this.issue(`${at}: assert "count" needs count: {eq|gte|lte: <n>}`);
|
|
25751
|
+
if (assert !== "count" && check.count !== void 0)
|
|
25752
|
+
this.issue(`${at}.count only goes with assert: "count"`);
|
|
25753
|
+
const predicate = assert === "all" || assert === "any";
|
|
25754
|
+
if (predicate && typeof check.field !== "string")
|
|
25755
|
+
this.issue(`${at}: assert "${assert}" needs field (and value) to test`);
|
|
25756
|
+
if (predicate && check.value === void 0)
|
|
25757
|
+
this.issue(`${at}: assert "${assert}" needs value to compare with`);
|
|
25758
|
+
if (!predicate && (check.field !== void 0 || check.op !== void 0 || check.value !== void 0))
|
|
25759
|
+
this.issue(`${at}.field/op/value only go with assert: "all" or "any"`);
|
|
25760
|
+
if (check.op !== void 0 && !oneOf(FIELD_OPS, check.op))
|
|
25761
|
+
this.issue(
|
|
25762
|
+
`${at}.op is one of ${listed(FIELD_OPS)}, got ${JSON.stringify(check.op)}`
|
|
25763
|
+
);
|
|
25764
|
+
}
|
|
25765
|
+
verifiers(verifiers) {
|
|
25766
|
+
if (verifiers === void 0) return;
|
|
25767
|
+
if (!Array.isArray(verifiers) || !verifiers.length)
|
|
25768
|
+
return this.issue(
|
|
25769
|
+
'verifiers is a non-empty list of {name, scope: ["<alias>", "<alias>", ...], kind, checks|source}'
|
|
25770
|
+
);
|
|
25771
|
+
const names = verifiers.map((v) => isRecord(v) ? v.name : void 0);
|
|
25772
|
+
verifiers.forEach((verifier, i) => {
|
|
25773
|
+
const at = `verifiers[${i}]`;
|
|
25774
|
+
if (typeof names[i] === "string" && repeatedAt(names, i))
|
|
25775
|
+
this.issue(`${at}.name "${names[i]}" is used twice`);
|
|
25776
|
+
this.verifier(verifier, at);
|
|
25777
|
+
});
|
|
25778
|
+
}
|
|
25779
|
+
verifier(verifier, at) {
|
|
25780
|
+
if (!isRecord(verifier))
|
|
25781
|
+
return this.issue(`${at} is an object {name, scope, kind, ...}`);
|
|
25782
|
+
if (typeof verifier.name !== "string" || !verifier.name)
|
|
25783
|
+
this.issue(`${at}.name names the verifier`);
|
|
25784
|
+
this.scope(verifier.scope, at);
|
|
25785
|
+
const keys = VERIFIER_KEYS.get(verifier.kind);
|
|
25786
|
+
if (!keys)
|
|
25787
|
+
return this.issue(
|
|
25788
|
+
`${at}.kind is assertions or python (a rubric cannot be a verifier)`
|
|
25789
|
+
);
|
|
25790
|
+
for (const k of Object.keys(verifier).filter((k2) => !keys.has(k2)))
|
|
25791
|
+
this.issue(
|
|
25792
|
+
`${at}.${k} is not a key of a verifier of kind ${verifier.kind} (${listed(keys)})`
|
|
25793
|
+
);
|
|
25794
|
+
this.grader(verifier, at);
|
|
25795
|
+
this.crossChecks(verifier, at);
|
|
25796
|
+
}
|
|
25797
|
+
scope(scope, at) {
|
|
25798
|
+
if (!isStringList(scope) || scope.length < 2)
|
|
25799
|
+
return this.issue(
|
|
25800
|
+
`${at}.scope lists two or more of the task's world aliases`
|
|
25801
|
+
);
|
|
25802
|
+
if (new Set(scope).size !== scope.length)
|
|
25803
|
+
this.issue(`${at}.scope lists each alias once`);
|
|
25804
|
+
this.scopeInWorlds(scope, at);
|
|
25805
|
+
this.anchor(scope[0], at);
|
|
25806
|
+
}
|
|
25807
|
+
scopeInWorlds(scope, at) {
|
|
25808
|
+
const worlds = this.spec.worlds;
|
|
25809
|
+
if (worlds === void 0 && scope[0] !== this.spec.name)
|
|
25810
|
+
this.issue(
|
|
25811
|
+
`${at}.scope[0] is "${scope[0]}", so the task's name must be "${scope[0]}": on a task without worlds a verifier runs on the session of its first scope alias`
|
|
25812
|
+
);
|
|
25813
|
+
if (!isRecord(worlds)) return;
|
|
25814
|
+
const aliases = Object.keys(worlds);
|
|
25815
|
+
for (const alias of scope.filter((a) => !aliases.includes(a)))
|
|
25816
|
+
this.issue(
|
|
25817
|
+
`${at}.scope names "${alias}", which is not one of worlds (${aliases.join(", ")})`
|
|
25818
|
+
);
|
|
25819
|
+
}
|
|
25820
|
+
anchor(alias, at) {
|
|
25821
|
+
const worlds = isRecord(this.spec.worlds) ? this.spec.worlds : {};
|
|
25822
|
+
const world = worlds[alias];
|
|
25823
|
+
const grader = (isRecord(world) ? world.grader : void 0) ?? this.spec.grader;
|
|
25824
|
+
if (!isRecord(grader) || grader.kind !== "rubric") return;
|
|
25825
|
+
this.issue(
|
|
25826
|
+
`${at} is anchored on "${alias}", whose grader is a rubric judged on the platform; anchor it (scope[0]) on a world graded by assertions, python or nothing`
|
|
24161
25827
|
);
|
|
25828
|
+
}
|
|
25829
|
+
crossChecks(verifier, at) {
|
|
25830
|
+
const { scope, checks } = verifier;
|
|
25831
|
+
if (verifier.kind !== "assertions") return;
|
|
25832
|
+
if (!isStringList(scope) || !Array.isArray(checks)) return;
|
|
25833
|
+
checks.forEach((check, i) => {
|
|
25834
|
+
const entity = isRecord(check) ? check.entity : void 0;
|
|
25835
|
+
if (typeof entity !== "string" || !entity) return;
|
|
25836
|
+
if (entity.includes(".") && scope.includes(entity.split(".")[0])) return;
|
|
25837
|
+
this.issue(
|
|
25838
|
+
`${at}.checks[${i}].entity is "${entity}": a cross-world check names its entity as <alias>.<entity> (or <alias>.calls) with the alias in scope (${scope.join(", ")})`
|
|
25839
|
+
);
|
|
25840
|
+
});
|
|
25841
|
+
}
|
|
25842
|
+
};
|
|
25843
|
+
function taskSpecIssues(spec) {
|
|
25844
|
+
return new TaskSpecCheck(spec).run();
|
|
24162
25845
|
}
|
|
24163
25846
|
function readTaskSpec(file, flag = "--spec") {
|
|
24164
25847
|
let parsed;
|
|
@@ -24169,7 +25852,7 @@ function readTaskSpec(file, flag = "--spec") {
|
|
|
24169
25852
|
`${flag} ${file}: ${error instanceof Error ? error.message : String(error)}`
|
|
24170
25853
|
);
|
|
24171
25854
|
}
|
|
24172
|
-
if (!
|
|
25855
|
+
if (!isRecord(parsed) || typeof parsed.instruction !== "string")
|
|
24173
25856
|
throw new CliError(
|
|
24174
25857
|
`${flag} ${file}: a task spec is a JSON object with an "instruction" string`
|
|
24175
25858
|
);
|
|
@@ -24183,12 +25866,37 @@ ${TASK_SPEC_HELP}`
|
|
|
24183
25866
|
);
|
|
24184
25867
|
return parsed;
|
|
24185
25868
|
}
|
|
25869
|
+
|
|
25870
|
+
// src/cli/platform/task.ts
|
|
25871
|
+
async function findTaskByName(name, options) {
|
|
25872
|
+
for (let page = 1; ; page++) {
|
|
25873
|
+
const batch = await listTasks({ page, limit: 100 }, options);
|
|
25874
|
+
const hit = batch.tasks.find((task) => task.name === name);
|
|
25875
|
+
if (hit) return hit;
|
|
25876
|
+
if (page >= batch.meta.totalPages) return null;
|
|
25877
|
+
}
|
|
25878
|
+
}
|
|
25879
|
+
var WORLD_FLAG = {
|
|
25880
|
+
name: "world",
|
|
25881
|
+
short: "w",
|
|
25882
|
+
help: "Pin the task to this world (slug); validated against its contract."
|
|
25883
|
+
};
|
|
25884
|
+
var NO_WORLD_FLAG = {
|
|
25885
|
+
name: "no-world",
|
|
25886
|
+
help: "Unpin the task so it can open on any world.",
|
|
25887
|
+
boolean: true
|
|
25888
|
+
};
|
|
25889
|
+
var MESSAGE_FLAG3 = {
|
|
25890
|
+
name: "message",
|
|
25891
|
+
short: "m",
|
|
25892
|
+
help: "Note kept with this version."
|
|
25893
|
+
};
|
|
24186
25894
|
async function loadTaskAgent(spec) {
|
|
24187
25895
|
const hash = spec.indexOf("#");
|
|
24188
25896
|
const file = hash === -1 ? spec : spec.slice(0, hash);
|
|
24189
25897
|
const exportName = hash === -1 ? void 0 : spec.slice(hash + 1);
|
|
24190
25898
|
const abs = path37.resolve(file);
|
|
24191
|
-
if (!
|
|
25899
|
+
if (!fs48.existsSync(abs)) throw new CliError(`--agent ${spec} does not exist`);
|
|
24192
25900
|
const ext = path37.extname(abs);
|
|
24193
25901
|
if (ext === ".ts" || ext === ".mts" || ext === ".cts")
|
|
24194
25902
|
await registerTypeScriptLoader(abs);
|
|
@@ -24214,7 +25922,7 @@ function worldFromFlags(world, noWorld) {
|
|
|
24214
25922
|
}
|
|
24215
25923
|
function readJsonFile(file, what) {
|
|
24216
25924
|
try {
|
|
24217
|
-
return JSON.parse(
|
|
25925
|
+
return JSON.parse(fs48.readFileSync(file, "utf8"));
|
|
24218
25926
|
} catch (error) {
|
|
24219
25927
|
throw new CliError(
|
|
24220
25928
|
`${what} ${file}: ${error instanceof Error ? error.message : String(error)}`
|
|
@@ -24222,7 +25930,7 @@ function readJsonFile(file, what) {
|
|
|
24222
25930
|
}
|
|
24223
25931
|
}
|
|
24224
25932
|
function taskTarget(positional) {
|
|
24225
|
-
if (!
|
|
25933
|
+
if (!fs48.existsSync(positional)) return { kind: "id", taskId: positional };
|
|
24226
25934
|
const parsed = readJsonFile(positional, "task");
|
|
24227
25935
|
if (isTaskManifest(parsed)) return { kind: "manifest", manifest: parsed };
|
|
24228
25936
|
if (parsed && typeof parsed === "object" && typeof parsed.instruction === "string")
|
|
@@ -24244,19 +25952,19 @@ var TARGET_POSITIONAL = {
|
|
|
24244
25952
|
help: "Task id, or the manifest file `task up --out` wrote."
|
|
24245
25953
|
};
|
|
24246
25954
|
function emitManifest(ctx, manifest, out) {
|
|
24247
|
-
if (out)
|
|
25955
|
+
if (out) fs48.writeFileSync(out, JSON.stringify(manifest, null, 2) + "\n");
|
|
24248
25956
|
printJson(ctx, manifest);
|
|
24249
25957
|
if (out) ctx.stderr(`wrote the manifest to ${out}`);
|
|
24250
25958
|
}
|
|
24251
25959
|
function pairsFromFlags(flag, pairs3) {
|
|
24252
25960
|
const out = {};
|
|
24253
|
-
for (const
|
|
24254
|
-
const eq =
|
|
25961
|
+
for (const pair3 of pairs3) {
|
|
25962
|
+
const eq = pair3.indexOf("=");
|
|
24255
25963
|
if (eq <= 0)
|
|
24256
25964
|
throw new CliError(
|
|
24257
|
-
`--${flag} takes key=value, got ${JSON.stringify(
|
|
25965
|
+
`--${flag} takes key=value, got ${JSON.stringify(pair3)}`
|
|
24258
25966
|
);
|
|
24259
|
-
out[
|
|
25967
|
+
out[pair3.slice(0, eq)] = pair3.slice(eq + 1);
|
|
24260
25968
|
}
|
|
24261
25969
|
return out;
|
|
24262
25970
|
}
|
|
@@ -24273,7 +25981,7 @@ function registerTaskCommands(root) {
|
|
|
24273
25981
|
positionals: [
|
|
24274
25982
|
{
|
|
24275
25983
|
name: "spec",
|
|
24276
|
-
help: "JSON file: {instruction, seed?, grader?, metadata?, name?}."
|
|
25984
|
+
help: "JSON file: {instruction, seed?, grader?, metadata?, name?, worlds?, verifiers?}."
|
|
24277
25985
|
}
|
|
24278
25986
|
],
|
|
24279
25987
|
flags: [
|
|
@@ -24492,7 +26200,7 @@ function registerTaskCommands(root) {
|
|
|
24492
26200
|
},
|
|
24493
26201
|
HOST_FLAG
|
|
24494
26202
|
],
|
|
24495
|
-
notes: "A task spec with `worlds` \u2014 {alias: {slug, ref?, seed?, grader?, tools?}} \u2014 is one instruction over several hosted\nworlds. `up` opens one session per alias (each on that world's own seed, grader and tools) in ONE platform call:\nif any world refuses, the ones that opened are closed and the error names every alias that failed, so nothing is\never half up. The manifest is keyed by alias; each entry is what `session open` prints for that world (api.url +\ntoken for --surface api). Later commands take the task id (finds the stored task's live sessions) or the manifest.",
|
|
26203
|
+
notes: "A task spec with `worlds` \u2014 {alias: {slug, ref?, seed?, grader?, tools?}} \u2014 is one instruction over several hosted\nworlds. `up` opens one session per alias (each on that world's own seed, grader and tools) in ONE platform call:\nif any world refuses, the ones that opened are closed and the error names every alias that failed, so nothing is\never half up. The manifest is keyed by alias; each entry is what `session open` prints for that world (api.url +\ntoken for --surface api). Later commands take the task id (finds the stored task's live sessions) or the manifest.\nA world where you have unsealed edits comes up at your tip (`private: true`); everyone else still gets shared main.\n`gateway worlds task edit status <task>` lists them; `task edit close <task>` seals them on every world at once.",
|
|
24496
26204
|
run: async (args, ctx) => {
|
|
24497
26205
|
const target = taskTarget(args.positionals[0]);
|
|
24498
26206
|
if (target.kind === "manifest")
|
|
@@ -24653,23 +26361,23 @@ function registerTaskCommands(root) {
|
|
|
24653
26361
|
const exported = await live.export();
|
|
24654
26362
|
const lines = [];
|
|
24655
26363
|
for (const [alias, calls] of Object.entries(exported))
|
|
24656
|
-
for (const
|
|
26364
|
+
for (const call3 of calls)
|
|
24657
26365
|
lines.push(
|
|
24658
26366
|
JSON.stringify({
|
|
24659
26367
|
world: alias,
|
|
24660
|
-
seq:
|
|
24661
|
-
kind:
|
|
24662
|
-
tool:
|
|
24663
|
-
args:
|
|
24664
|
-
result:
|
|
24665
|
-
error:
|
|
24666
|
-
completedAt:
|
|
26368
|
+
seq: call3.seq,
|
|
26369
|
+
kind: call3.kind,
|
|
26370
|
+
tool: call3.tool,
|
|
26371
|
+
args: call3.args,
|
|
26372
|
+
result: call3.result,
|
|
26373
|
+
error: call3.error,
|
|
26374
|
+
completedAt: call3.completedAt
|
|
24667
26375
|
})
|
|
24668
26376
|
);
|
|
24669
26377
|
const text2 = lines.join("\n") + (lines.length ? "\n" : "");
|
|
24670
26378
|
const out = arg.str(args, "out");
|
|
24671
26379
|
if (out) {
|
|
24672
|
-
|
|
26380
|
+
fs48.writeFileSync(out, text2);
|
|
24673
26381
|
ctx.stdout(
|
|
24674
26382
|
`wrote ${lines.length} calls from ${Object.keys(exported).length} worlds to ${out}`
|
|
24675
26383
|
);
|
|
@@ -25112,7 +26820,7 @@ source (bundled|stored|inline|none)/name/hash/id/version.
|
|
|
25112
26820
|
try {
|
|
25113
26821
|
const url = await browser.goto(arg.str(args, "path"));
|
|
25114
26822
|
const shot = arg.str(args, "screenshot");
|
|
25115
|
-
if (shot)
|
|
26823
|
+
if (shot) fs49.writeFileSync(shot, await browser.screenshot());
|
|
25116
26824
|
printJson(ctx, {
|
|
25117
26825
|
url,
|
|
25118
26826
|
title: await browser.title(),
|
|
@@ -25238,21 +26946,21 @@ world's [redact] policy over the rows first; --redact refuse rejects plaintext i
|
|
|
25238
26946
|
);
|
|
25239
26947
|
const deadline = Date.now() + SEED_TIMEOUT_MS;
|
|
25240
26948
|
for (; ; ) {
|
|
25241
|
-
const
|
|
26949
|
+
const call3 = await api(
|
|
25242
26950
|
creds,
|
|
25243
26951
|
"GET",
|
|
25244
26952
|
`${sessionRoute(sessionId)}/calls/${encodeURIComponent(callId)}`
|
|
25245
26953
|
);
|
|
25246
|
-
const settled =
|
|
26954
|
+
const settled = call3.done || call3.state === "completed" || call3.state === "failed";
|
|
25247
26955
|
if (settled) {
|
|
25248
|
-
if (
|
|
25249
|
-
throw new CliError(
|
|
25250
|
-
printJson(ctx, { sessionId, mode, ...redact2 !== "off" ? { redact: redact2 } : {}, result:
|
|
26956
|
+
if (call3.error || call3.state === "failed")
|
|
26957
|
+
throw new CliError(call3.error ?? "seed failed", 1);
|
|
26958
|
+
printJson(ctx, { sessionId, mode, ...redact2 !== "off" ? { redact: redact2 } : {}, result: call3.result });
|
|
25251
26959
|
return;
|
|
25252
26960
|
}
|
|
25253
26961
|
if (Date.now() > deadline)
|
|
25254
26962
|
throw new CliError(
|
|
25255
|
-
`Seed call ${callId} still ${
|
|
26963
|
+
`Seed call ${callId} still ${call3.state} after ${SEED_TIMEOUT_MS / 1e3}s.`,
|
|
25256
26964
|
1
|
|
25257
26965
|
);
|
|
25258
26966
|
await sleep2(SEED_POLL_MS);
|
|
@@ -25285,9 +26993,9 @@ world's [redact] policy over the rows first; --redact refuse rejects plaintext i
|
|
|
25285
26993
|
cursor = page.nextCursor ?? void 0;
|
|
25286
26994
|
} while (cursor);
|
|
25287
26995
|
const lines = calls.map(
|
|
25288
|
-
(
|
|
26996
|
+
(call3) => JSON.stringify(
|
|
25289
26997
|
Object.fromEntries(
|
|
25290
|
-
EXPORT_KEYS.map((key2) => [key2,
|
|
26998
|
+
EXPORT_KEYS.map((key2) => [key2, call3[key2] ?? null])
|
|
25291
26999
|
)
|
|
25292
27000
|
)
|
|
25293
27001
|
);
|
|
@@ -25295,12 +27003,12 @@ world's [redact] policy over the rows first; --redact refuse rejects plaintext i
|
|
|
25295
27003
|
const out = arg.str(args, "out");
|
|
25296
27004
|
const to = arg.str(args, "to");
|
|
25297
27005
|
if (out) {
|
|
25298
|
-
|
|
27006
|
+
fs49.writeFileSync(out, text2);
|
|
25299
27007
|
ctx.stdout(`wrote ${lines.length} calls to ${out}`);
|
|
25300
27008
|
} else if (!to && text2) process.stdout.write(text2);
|
|
25301
27009
|
if (!to) return;
|
|
25302
27010
|
const scratch = out ? null : scratchFile(`${sessionId}.calls.jsonl`);
|
|
25303
|
-
if (scratch)
|
|
27011
|
+
if (scratch) fs49.writeFileSync(scratch.file, text2);
|
|
25304
27012
|
try {
|
|
25305
27013
|
const landed = await landInDrive(scratch?.file ?? out, to, creds);
|
|
25306
27014
|
ctx.stdout(`wrote ${lines.length} calls to drive:${landed.path}`);
|
|
@@ -25314,6 +27022,166 @@ world's [redact] policy over the rows first; --redact refuse rejects plaintext i
|
|
|
25314
27022
|
// src/cli/platform/index.ts
|
|
25315
27023
|
init_skill();
|
|
25316
27024
|
|
|
27025
|
+
// src/cli/platform/taskEditVerbs.ts
|
|
27026
|
+
init_config();
|
|
27027
|
+
init_router();
|
|
27028
|
+
init_editSessions();
|
|
27029
|
+
init_worlds();
|
|
27030
|
+
init_shared();
|
|
27031
|
+
var TASK_POSITIONAL = {
|
|
27032
|
+
name: "task",
|
|
27033
|
+
help: "Task id, a spec file with a `worlds` table, or the manifest `task up --out` wrote."
|
|
27034
|
+
};
|
|
27035
|
+
var TASK_VERSION_FLAG = {
|
|
27036
|
+
name: "task-version",
|
|
27037
|
+
help: "With a task id: that version's worlds instead of the current one's."
|
|
27038
|
+
};
|
|
27039
|
+
var MESSAGE_FLAG4 = {
|
|
27040
|
+
name: "message",
|
|
27041
|
+
short: "m",
|
|
27042
|
+
help: "Change reason recorded on every session it seals or writes (and on a version a rebase writes), shown in History."
|
|
27043
|
+
};
|
|
27044
|
+
function taskEditTarget(positional, version) {
|
|
27045
|
+
const target = taskTarget(positional);
|
|
27046
|
+
if (target.kind === "id")
|
|
27047
|
+
return { id: target.taskId, ...version === void 0 ? {} : { version } };
|
|
27048
|
+
if (target.kind === "spec") {
|
|
27049
|
+
if (!target.spec.worlds)
|
|
27050
|
+
throw new CliError(
|
|
27051
|
+
"task edit needs a spec that names its worlds ({instruction, worlds: {alias: {slug, \u2026}}}); for one world use `gateway worlds edit`"
|
|
27052
|
+
);
|
|
27053
|
+
return target.spec;
|
|
27054
|
+
}
|
|
27055
|
+
const { manifest } = target;
|
|
27056
|
+
if (manifest.taskId)
|
|
27057
|
+
return {
|
|
27058
|
+
id: manifest.taskId,
|
|
27059
|
+
...manifest.taskVersion === null ? {} : { version: manifest.taskVersion }
|
|
27060
|
+
};
|
|
27061
|
+
return {
|
|
27062
|
+
instruction: manifest.instruction ?? "task",
|
|
27063
|
+
worlds: Object.fromEntries(
|
|
27064
|
+
Object.entries(manifest.sessions).map(([alias, s]) => [
|
|
27065
|
+
alias,
|
|
27066
|
+
{ slug: s.slug, ...s.ref ? { ref: s.ref } : {} }
|
|
27067
|
+
])
|
|
27068
|
+
)
|
|
27069
|
+
};
|
|
27070
|
+
}
|
|
27071
|
+
function client3(args) {
|
|
27072
|
+
return new TaskEditClient(worldsOptions(credentials(args)));
|
|
27073
|
+
}
|
|
27074
|
+
async function call2(run) {
|
|
27075
|
+
try {
|
|
27076
|
+
return await run();
|
|
27077
|
+
} catch (error) {
|
|
27078
|
+
if (error instanceof ApiError)
|
|
27079
|
+
throw new CliError(`Error: ${error.message}`, 1);
|
|
27080
|
+
throw error;
|
|
27081
|
+
}
|
|
27082
|
+
}
|
|
27083
|
+
function registerTaskEditVerbs(root) {
|
|
27084
|
+
const edit = root.group("worlds", "Build, seed, serve and run worlds.").group(
|
|
27085
|
+
"task",
|
|
27086
|
+
"Stored tasks: instruction + seed + grader kept by the project, outside any bundle."
|
|
27087
|
+
).group(
|
|
27088
|
+
"edit",
|
|
27089
|
+
"Edit sessions across every world a task names: see what this credential has not sealed, seal every world onto main in one step (all or none), roll the group back together."
|
|
27090
|
+
);
|
|
27091
|
+
edit.command({
|
|
27092
|
+
name: "status",
|
|
27093
|
+
output: "json",
|
|
27094
|
+
help: "Per world of the task: this credential's open edit session (edits, base, tip) and what sealing now would do (fast-forward, rebase or conflict with its paths); `unsealed` lists the worlds holding edits only you see.",
|
|
27095
|
+
positionals: [TASK_POSITIONAL],
|
|
27096
|
+
flags: [TASK_VERSION_FLAG, HOST_FLAG],
|
|
27097
|
+
notes: "Your own `task up` opens the worlds listed under `unsealed` at your tip (`private: true`); colleagues, run configs\nand schedules keep shared main until `task edit close` seals them. `parked` lists sessions stuck in conflict.",
|
|
27098
|
+
run: async (args, ctx) => {
|
|
27099
|
+
const task = taskEditTarget(
|
|
27100
|
+
args.positionals[0],
|
|
27101
|
+
arg.int(args, "task-version")
|
|
27102
|
+
);
|
|
27103
|
+
printJson(ctx, await call2(() => client3(args).status(task)));
|
|
27104
|
+
}
|
|
27105
|
+
});
|
|
27106
|
+
edit.command({
|
|
27107
|
+
name: "close",
|
|
27108
|
+
help: "Seal this credential's open edit session on every world of the task in ONE step: every main moves, or none does. Prints {groupId, worlds: {alias: {slug, session}}, skipped}.",
|
|
27109
|
+
positionals: [TASK_POSITIONAL],
|
|
27110
|
+
flags: [
|
|
27111
|
+
TASK_VERSION_FLAG,
|
|
27112
|
+
{
|
|
27113
|
+
name: "require-all",
|
|
27114
|
+
help: "Refuse unless every world has an open edit to seal (default: skip those that have none and list them).",
|
|
27115
|
+
boolean: true
|
|
27116
|
+
},
|
|
27117
|
+
{
|
|
27118
|
+
name: "force",
|
|
27119
|
+
help: "Where main moved under a session on the same paths, keep the session's files instead of refusing the whole close.",
|
|
27120
|
+
boolean: true
|
|
27121
|
+
},
|
|
27122
|
+
MESSAGE_FLAG4,
|
|
27123
|
+
HOST_FLAG
|
|
27124
|
+
],
|
|
27125
|
+
notes: "Each world seals as `gateway worlds edit close` would: a fast-forward, or a rebase when main moved on other\npaths. If any world conflicts, is missing, names a ref other than main, holds a session of yours parked in\nconflict, or fails, NOTHING is sealed and the error (exit 1) names every world's problem. The sessions share\n`groupId`: `task edit rollback --group` undoes them.",
|
|
27126
|
+
run: async (args, ctx) => {
|
|
27127
|
+
const task = taskEditTarget(
|
|
27128
|
+
args.positionals[0],
|
|
27129
|
+
arg.int(args, "task-version")
|
|
27130
|
+
);
|
|
27131
|
+
printJson(
|
|
27132
|
+
ctx,
|
|
27133
|
+
await call2(
|
|
27134
|
+
() => client3(args).close(task, {
|
|
27135
|
+
requireAll: arg.bool(args, "require-all") || void 0,
|
|
27136
|
+
force: arg.bool(args, "force") || void 0,
|
|
27137
|
+
message: arg.str(args, "message")
|
|
27138
|
+
})
|
|
27139
|
+
)
|
|
27140
|
+
);
|
|
27141
|
+
}
|
|
27142
|
+
});
|
|
27143
|
+
edit.command({
|
|
27144
|
+
name: "rollback",
|
|
27145
|
+
help: "Undo a seal group: every world's main returns to the source and data it had before the group, in one step, as new sealed sessions sharing a new groupId (so the rollback is itself reversible).",
|
|
27146
|
+
positionals: [TASK_POSITIONAL],
|
|
27147
|
+
flags: [
|
|
27148
|
+
TASK_VERSION_FLAG,
|
|
27149
|
+
{
|
|
27150
|
+
name: "group",
|
|
27151
|
+
help: "The groupId `task edit close` printed (required)."
|
|
27152
|
+
},
|
|
27153
|
+
{
|
|
27154
|
+
name: "force",
|
|
27155
|
+
help: "Also undo what reached those worlds' main after the group: later sessions or writes outside sessions (refused without it).",
|
|
27156
|
+
boolean: true
|
|
27157
|
+
},
|
|
27158
|
+
MESSAGE_FLAG4,
|
|
27159
|
+
HOST_FLAG
|
|
27160
|
+
],
|
|
27161
|
+
run: async (args, ctx) => {
|
|
27162
|
+
const groupId = arg.str(args, "group");
|
|
27163
|
+
if (!groupId)
|
|
27164
|
+
throw new CliError(
|
|
27165
|
+
"task edit rollback needs --group <groupId> (printed by `task edit close`)"
|
|
27166
|
+
);
|
|
27167
|
+
const task = taskEditTarget(
|
|
27168
|
+
args.positionals[0],
|
|
27169
|
+
arg.int(args, "task-version")
|
|
27170
|
+
);
|
|
27171
|
+
printJson(
|
|
27172
|
+
ctx,
|
|
27173
|
+
await call2(
|
|
27174
|
+
() => client3(args).rollback(task, {
|
|
27175
|
+
groupId,
|
|
27176
|
+
force: arg.bool(args, "force") || void 0,
|
|
27177
|
+
message: arg.str(args, "message")
|
|
27178
|
+
})
|
|
27179
|
+
)
|
|
27180
|
+
);
|
|
27181
|
+
}
|
|
27182
|
+
});
|
|
27183
|
+
}
|
|
27184
|
+
|
|
25317
27185
|
// src/cli/platform/taskRunSet.ts
|
|
25318
27186
|
init_config();
|
|
25319
27187
|
init_router();
|
|
@@ -25398,7 +27266,7 @@ function registerTaskRunSet(root) {
|
|
|
25398
27266
|
}
|
|
25399
27267
|
|
|
25400
27268
|
// src/cli/platform/traces.ts
|
|
25401
|
-
var
|
|
27269
|
+
var fs50 = __toESM(require("fs"));
|
|
25402
27270
|
init_config();
|
|
25403
27271
|
init_router();
|
|
25404
27272
|
|
|
@@ -25559,11 +27427,11 @@ function registerTracesCommands(root) {
|
|
|
25559
27427
|
flags: [...FILTER_FLAGS, { name: "limit", help: "At most this many (pages of 100 underneath).", default: "50" }, JSON_FLAG3, HOST_FLAG],
|
|
25560
27428
|
run: async (args, ctx) => {
|
|
25561
27429
|
const options = worldsOptions(credentials(args));
|
|
25562
|
-
const
|
|
25563
|
-
for await (const trace3 of iterateTraces(options, filtersOf(args), { max: limitOf(args, 50) }))
|
|
25564
|
-
if (arg.bool(args, "json")) return void printJson(ctx,
|
|
25565
|
-
if (!
|
|
25566
|
-
for (const trace3 of
|
|
27430
|
+
const listed2 = [];
|
|
27431
|
+
for await (const trace3 of iterateTraces(options, filtersOf(args), { max: limitOf(args, 50) })) listed2.push(trace3);
|
|
27432
|
+
if (arg.bool(args, "json")) return void printJson(ctx, listed2);
|
|
27433
|
+
if (!listed2.length) return void ctx.stderr("no traces match");
|
|
27434
|
+
for (const trace3 of listed2) ctx.stdout(traceLine(trace3));
|
|
25567
27435
|
}
|
|
25568
27436
|
});
|
|
25569
27437
|
traces.command({
|
|
@@ -25617,7 +27485,7 @@ function registerTracesCommands(root) {
|
|
|
25617
27485
|
const scratch = toDrive ? scratchFile("traces.jsonl") : null;
|
|
25618
27486
|
const file = toStdout ? null : scratch?.file ?? out;
|
|
25619
27487
|
try {
|
|
25620
|
-
const sink = file ?
|
|
27488
|
+
const sink = file ? fs50.createWriteStream(file) : null;
|
|
25621
27489
|
const write = (record) => {
|
|
25622
27490
|
const line = JSON.stringify(record) + "\n";
|
|
25623
27491
|
if (sink) sink.write(line);
|
|
@@ -25648,11 +27516,11 @@ function registerTracesCommands(root) {
|
|
|
25648
27516
|
],
|
|
25649
27517
|
run: async (args, ctx) => {
|
|
25650
27518
|
const filters = { fromTimestamp: arg.str(args, "from"), toTimestamp: arg.str(args, "to"), environment: arg.str(args, "environment") };
|
|
25651
|
-
const
|
|
25652
|
-
for await (const session of iterateSessions(worldsOptions(credentials(args)), filters, { max: limitOf(args, 50) }))
|
|
25653
|
-
if (arg.bool(args, "json")) return void printJson(ctx,
|
|
25654
|
-
if (!
|
|
25655
|
-
for (const session of
|
|
27519
|
+
const listed2 = [];
|
|
27520
|
+
for await (const session of iterateSessions(worldsOptions(credentials(args)), filters, { max: limitOf(args, 50) })) listed2.push(session);
|
|
27521
|
+
if (arg.bool(args, "json")) return void printJson(ctx, listed2);
|
|
27522
|
+
if (!listed2.length) return void ctx.stderr("no sessions match");
|
|
27523
|
+
for (const session of listed2) ctx.stdout(`${session.id} ${session.createdAt} ${session.environment}`);
|
|
25656
27524
|
}
|
|
25657
27525
|
});
|
|
25658
27526
|
sessions.command({
|
|
@@ -25735,8 +27603,8 @@ function registerTracesCommands(root) {
|
|
|
25735
27603
|
});
|
|
25736
27604
|
}
|
|
25737
27605
|
function readFile2(file) {
|
|
25738
|
-
if (!
|
|
25739
|
-
return
|
|
27606
|
+
if (!fs50.existsSync(file)) throw new CliError(`${file} does not exist`, 1);
|
|
27607
|
+
return fs50.readFileSync(file, "utf8");
|
|
25740
27608
|
}
|
|
25741
27609
|
|
|
25742
27610
|
// src/cli/platform/worldData/chunks.ts
|
|
@@ -25924,6 +27792,7 @@ function registerPlatformCommands(root) {
|
|
|
25924
27792
|
registerSessionCommands(root);
|
|
25925
27793
|
registerTaskCommands(root);
|
|
25926
27794
|
registerTaskRunSet(root);
|
|
27795
|
+
registerTaskEditVerbs(root);
|
|
25927
27796
|
registerConnectorCommands(root);
|
|
25928
27797
|
registerSkillCommands(root);
|
|
25929
27798
|
registerDataCommands(root);
|
|
@@ -25941,7 +27810,7 @@ function registerPlatformCommands(root) {
|
|
|
25941
27810
|
init_schema();
|
|
25942
27811
|
|
|
25943
27812
|
// src/cli/runtime/connector.ts
|
|
25944
|
-
var
|
|
27813
|
+
var fs51 = __toESM(require("fs"));
|
|
25945
27814
|
var path38 = __toESM(require("path"));
|
|
25946
27815
|
init_router();
|
|
25947
27816
|
init_config();
|
|
@@ -25977,9 +27846,9 @@ function wireParams(params) {
|
|
|
25977
27846
|
}
|
|
25978
27847
|
function requireConnectorToml(dir) {
|
|
25979
27848
|
const file = path38.join(dir, "connector.toml");
|
|
25980
|
-
if (!
|
|
27849
|
+
if (!fs51.existsSync(file))
|
|
25981
27850
|
throw new CliError(`${dir} holds no connector.toml`, 1);
|
|
25982
|
-
return
|
|
27851
|
+
return fs51.readFileSync(file, "utf8");
|
|
25983
27852
|
}
|
|
25984
27853
|
function renderConnection(spec) {
|
|
25985
27854
|
const lines = [`${spec.slug} ${spec.baseUrl} auth=${spec.auth}`];
|
|
@@ -26071,9 +27940,9 @@ async function remoteCapture(creds, world, opts, ctx) {
|
|
|
26071
27940
|
if (!res.ok)
|
|
26072
27941
|
throw new CliError(`download ${drivePath2} -> ${res.status}`, 1);
|
|
26073
27942
|
const destination = path38.join(world, relative4);
|
|
26074
|
-
|
|
27943
|
+
fs51.mkdirSync(path38.dirname(destination), { recursive: true });
|
|
26075
27944
|
const bytes = Buffer.from(await res.arrayBuffer());
|
|
26076
|
-
|
|
27945
|
+
fs51.writeFileSync(destination, bytes);
|
|
26077
27946
|
written.push(relative4);
|
|
26078
27947
|
for (const name of undeclaredParams(bytes))
|
|
26079
27948
|
ctx.stderr(
|
|
@@ -26081,7 +27950,7 @@ async function remoteCapture(creds, world, opts, ctx) {
|
|
|
26081
27950
|
);
|
|
26082
27951
|
}
|
|
26083
27952
|
const manifestPath2 = path38.join(world, CAPTURES, MANIFEST);
|
|
26084
|
-
const existing =
|
|
27953
|
+
const existing = fs51.existsSync(manifestPath2) ? JSON.parse(fs51.readFileSync(manifestPath2, "utf8")) : [];
|
|
26085
27954
|
const known = new Set(
|
|
26086
27955
|
existing.map(
|
|
26087
27956
|
(e) => e && typeof e === "object" ? e.file : void 0
|
|
@@ -26094,8 +27963,8 @@ async function remoteCapture(creds, world, opts, ctx) {
|
|
|
26094
27963
|
existing.push(entry);
|
|
26095
27964
|
known.add(file);
|
|
26096
27965
|
}
|
|
26097
|
-
|
|
26098
|
-
|
|
27966
|
+
fs51.mkdirSync(path38.dirname(manifestPath2), { recursive: true });
|
|
27967
|
+
fs51.writeFileSync(manifestPath2, sortedJson(existing, 1) + "\n");
|
|
26099
27968
|
return written;
|
|
26100
27969
|
}
|
|
26101
27970
|
function outcomeOk(outcome) {
|
|
@@ -26185,8 +28054,8 @@ function registerConnectorCommands2(connector) {
|
|
|
26185
28054
|
`local capture runs the vendor call from this machine and needs python3 >= 3.12 (the CLI bundles the runtime). ${localRuntimeReason()} Or use --remote to capture from the platform.`
|
|
26186
28055
|
);
|
|
26187
28056
|
const argv = ["connector-capture", dir, "--op", op];
|
|
26188
|
-
for (const
|
|
26189
|
-
for (const
|
|
28057
|
+
for (const pair3 of arg.list(args, "arg")) argv.push("--arg", pair3);
|
|
28058
|
+
for (const pair3 of arg.list(args, "param")) argv.push("--param", pair3);
|
|
26190
28059
|
const maxPages = arg.int(args, "max-pages");
|
|
26191
28060
|
if (maxPages !== void 0) argv.push("--max-pages", String(maxPages));
|
|
26192
28061
|
return localModule(argv, local);
|
|
@@ -26231,11 +28100,11 @@ function registerConnectorCommands2(connector) {
|
|
|
26231
28100
|
throw new CliError("conform needs --openapi FILE (repeatable)");
|
|
26232
28101
|
requireConnectorToml(dir);
|
|
26233
28102
|
const openapi = documents.map((file) => {
|
|
26234
|
-
if (!
|
|
28103
|
+
if (!fs51.existsSync(file))
|
|
26235
28104
|
throw new CliError(`--openapi ${file} does not exist`);
|
|
26236
28105
|
return {
|
|
26237
28106
|
path: path38.basename(file),
|
|
26238
|
-
content:
|
|
28107
|
+
content: fs51.readFileSync(file).toString("base64")
|
|
26239
28108
|
};
|
|
26240
28109
|
});
|
|
26241
28110
|
const limit = arg.int(args, "limit");
|
|
@@ -26253,7 +28122,7 @@ function registerConnectorCommands2(connector) {
|
|
|
26253
28122
|
ctx.stdout(JSON.stringify(summary2));
|
|
26254
28123
|
const out = arg.str(args, "out");
|
|
26255
28124
|
if (out) {
|
|
26256
|
-
|
|
28125
|
+
fs51.writeFileSync(out, JSON.stringify(report, null, 1) + "\n");
|
|
26257
28126
|
ctx.stdout(`report: ${out}`);
|
|
26258
28127
|
}
|
|
26259
28128
|
return Number(summary2.status_mismatch) || Number(summary2.schema_violations) ? 1 : 0;
|
|
@@ -26282,7 +28151,7 @@ function registerConnectorCommands2(connector) {
|
|
|
26282
28151
|
notes: "An ingest stops at the first row the contract refuses; --dry-run reports all of them at once, grouped\nby capture, entity and pointer, so a forty-capture world is fixed in one pass. Exit 2 when any row is refused.",
|
|
26283
28152
|
run: async (args, ctx) => {
|
|
26284
28153
|
const dir = path38.resolve(args.positionals[0]);
|
|
26285
|
-
if (!
|
|
28154
|
+
if (!fs51.existsSync(path38.join(dir, CAPTURES)))
|
|
26286
28155
|
throw new CliError(
|
|
26287
28156
|
`${dir} holds no ${CAPTURES}/ \u2014 run \`connector capture --remote\` first`,
|
|
26288
28157
|
1
|
|
@@ -26313,7 +28182,7 @@ function registerConnectorCommands2(connector) {
|
|
|
26313
28182
|
` ${refusal.capture ?? "?"} ${refusal.pointer}: ${refusal.detail}`
|
|
26314
28183
|
);
|
|
26315
28184
|
if (report) {
|
|
26316
|
-
|
|
28185
|
+
fs51.writeFileSync(
|
|
26317
28186
|
report,
|
|
26318
28187
|
refusals.map((r) => JSON.stringify(r) + "\n").join("")
|
|
26319
28188
|
);
|
|
@@ -26340,12 +28209,12 @@ function registerConnectorCommands2(connector) {
|
|
|
26340
28209
|
}
|
|
26341
28210
|
|
|
26342
28211
|
// src/cli/runtime/serve.ts
|
|
26343
|
-
var
|
|
28212
|
+
var fs52 = __toESM(require("fs"));
|
|
26344
28213
|
var path39 = __toESM(require("path"));
|
|
26345
28214
|
init_router();
|
|
26346
28215
|
init_config();
|
|
26347
28216
|
init_worlds();
|
|
26348
|
-
|
|
28217
|
+
init_session2();
|
|
26349
28218
|
init_hub();
|
|
26350
28219
|
init_local();
|
|
26351
28220
|
function registerServeCommand(worlds) {
|
|
@@ -26390,7 +28259,7 @@ function registerServeCommand(worlds) {
|
|
|
26390
28259
|
run: async (args, ctx) => {
|
|
26391
28260
|
const target = args.positionals[0];
|
|
26392
28261
|
const local = localRuntime();
|
|
26393
|
-
if (local &&
|
|
28262
|
+
if (local && fs52.existsSync(target) && fs52.statSync(target).isDirectory()) {
|
|
26394
28263
|
const port = arg.int(args, "port") ?? 8080;
|
|
26395
28264
|
if (!Number.isInteger(port) || port < 0 || port > 65535)
|
|
26396
28265
|
throw new CliError(
|
|
@@ -26411,7 +28280,7 @@ function registerServeCommand(worlds) {
|
|
|
26411
28280
|
);
|
|
26412
28281
|
return localModule(argv, local);
|
|
26413
28282
|
}
|
|
26414
|
-
if (!local &&
|
|
28283
|
+
if (!local && fs52.existsSync(target) && fs52.statSync(target).isDirectory())
|
|
26415
28284
|
ctx.stderr(
|
|
26416
28285
|
`# ${localRuntimeReason()}
|
|
26417
28286
|
# A local directory is served here only by the bundled Python runtime; without one the CLI can only open a hosted session of a world already published (gateway worlds create <slug> --from ${target}), which needs a login (gateway auth login).`
|
|
@@ -26424,7 +28293,7 @@ function registerServeCommand(worlds) {
|
|
|
26424
28293
|
};
|
|
26425
28294
|
let slugRef = target;
|
|
26426
28295
|
let versionId;
|
|
26427
|
-
if (
|
|
28296
|
+
if (fs52.existsSync(target) && fs52.statSync(target).isDirectory()) {
|
|
26428
28297
|
const dir = path39.resolve(target);
|
|
26429
28298
|
const meta = readLocalMeta(dir);
|
|
26430
28299
|
const slug = meta?.slug ?? path39.basename(dir);
|
|
@@ -26434,7 +28303,7 @@ function registerServeCommand(worlds) {
|
|
|
26434
28303
|
ctx.stderr(
|
|
26435
28304
|
"`worlds serve` runs a local session with the Python runtime; opening a hosted api-surface session instead."
|
|
26436
28305
|
);
|
|
26437
|
-
if (!local && !(
|
|
28306
|
+
if (!local && !(fs52.existsSync(target) && fs52.statSync(target).isDirectory())) ctx.stderr(`# ${localRuntimeReason()}`);
|
|
26438
28307
|
let scenario = arg.str(args, "scenario") ?? arg.str(args, "task");
|
|
26439
28308
|
if (!scenario) {
|
|
26440
28309
|
const world = await openWorld(slugRef, options);
|
|
@@ -26472,7 +28341,7 @@ function registerServeCommand(worlds) {
|
|
|
26472
28341
|
}
|
|
26473
28342
|
|
|
26474
28343
|
// src/cli/runtime/test.ts
|
|
26475
|
-
var
|
|
28344
|
+
var fs53 = __toESM(require("fs"));
|
|
26476
28345
|
var path40 = __toESM(require("path"));
|
|
26477
28346
|
init_router();
|
|
26478
28347
|
init_shared();
|
|
@@ -26534,7 +28403,7 @@ function registerTestCommand(worlds) {
|
|
|
26534
28403
|
run: async (args, ctx) => {
|
|
26535
28404
|
const target = args.positionals[0] ?? ".";
|
|
26536
28405
|
const dir = path40.resolve(target);
|
|
26537
|
-
if (!
|
|
28406
|
+
if (!fs53.existsSync(dir) || !fs53.statSync(dir).isDirectory()) {
|
|
26538
28407
|
if (/[\/\\]/.test(target) || target.startsWith("."))
|
|
26539
28408
|
throw new CliError(`Not a directory: ${dir}`, 1);
|
|
26540
28409
|
const creds2 = resolveCredentials(arg.str(args, "host"));
|
|
@@ -26601,7 +28470,7 @@ function registerTestCommand(worlds) {
|
|
|
26601
28470
|
}
|
|
26602
28471
|
const out2 = arg.str(args, "out");
|
|
26603
28472
|
if (out2)
|
|
26604
|
-
|
|
28473
|
+
fs53.writeFileSync(
|
|
26605
28474
|
out2,
|
|
26606
28475
|
JSON.stringify(
|
|
26607
28476
|
{
|
|
@@ -26630,7 +28499,7 @@ function registerTestCommand(worlds) {
|
|
|
26630
28499
|
const s = report.summary ?? {};
|
|
26631
28500
|
if (!(s.total ?? 0) && !(report.python?.files?.length ?? 0)) {
|
|
26632
28501
|
const tests = path40.join(dir, "tests");
|
|
26633
|
-
const state2 =
|
|
28502
|
+
const state2 = fs53.existsSync(tests) ? "holds none" : "does not exist";
|
|
26634
28503
|
ctx.stdout(`no cases: ${tests} ${state2} (see \`gateway worlds test --help\` for the shapes)`);
|
|
26635
28504
|
}
|
|
26636
28505
|
ctx.stdout(
|
|
@@ -26639,7 +28508,7 @@ function registerTestCommand(worlds) {
|
|
|
26639
28508
|
}
|
|
26640
28509
|
const out = arg.str(args, "out");
|
|
26641
28510
|
if (out) {
|
|
26642
|
-
|
|
28511
|
+
fs53.writeFileSync(out, JSON.stringify(report, null, 1) + "\n");
|
|
26643
28512
|
ctx.stdout(`report: ${out}`);
|
|
26644
28513
|
}
|
|
26645
28514
|
return report.summary?.status === "passed" ? 0 : 1;
|
|
@@ -26648,10 +28517,10 @@ function registerTestCommand(worlds) {
|
|
|
26648
28517
|
}
|
|
26649
28518
|
|
|
26650
28519
|
// src/cli/runtime/call.ts
|
|
26651
|
-
var
|
|
28520
|
+
var fs54 = __toESM(require("fs"));
|
|
26652
28521
|
var path41 = __toESM(require("path"));
|
|
26653
28522
|
init_router();
|
|
26654
|
-
|
|
28523
|
+
init_session2();
|
|
26655
28524
|
init_sessionContract();
|
|
26656
28525
|
init_shared();
|
|
26657
28526
|
init_local();
|
|
@@ -26663,8 +28532,8 @@ function parseArgs2(raw, stdin) {
|
|
|
26663
28532
|
if (raw === "-") text2 = stdin;
|
|
26664
28533
|
else if (raw.startsWith("@")) {
|
|
26665
28534
|
const file = raw.slice(1);
|
|
26666
|
-
if (!
|
|
26667
|
-
text2 =
|
|
28535
|
+
if (!fs54.existsSync(file)) throw new CliError(`--args ${raw}: ${file} does not exist`);
|
|
28536
|
+
text2 = fs54.readFileSync(file, "utf8");
|
|
26668
28537
|
}
|
|
26669
28538
|
let value;
|
|
26670
28539
|
try {
|
|
@@ -26739,7 +28608,7 @@ async function callHosted(sessionId, tool, args, wants, options) {
|
|
|
26739
28608
|
return settleStatus(report);
|
|
26740
28609
|
}
|
|
26741
28610
|
function looksLikeSessionId(target) {
|
|
26742
|
-
return !target.includes("/") && !target.startsWith(".") && !
|
|
28611
|
+
return !target.includes("/") && !target.startsWith(".") && !fs54.existsSync(target);
|
|
26743
28612
|
}
|
|
26744
28613
|
async function callServed(base, tool, args, wants) {
|
|
26745
28614
|
const url = base.replace(/\/+$/, "");
|
|
@@ -26859,7 +28728,7 @@ Examples:
|
|
|
26859
28728
|
}
|
|
26860
28729
|
if (arg.bool(args, "close")) throw new CliError("--close ends a served or hosted session; pass its url or id instead of a directory");
|
|
26861
28730
|
const dir = path41.resolve(target);
|
|
26862
|
-
if (!
|
|
28731
|
+
if (!fs54.existsSync(dir) || !fs54.statSync(dir).isDirectory()) throw new CliError(`Not a directory: ${dir}`, 1);
|
|
26863
28732
|
const local = localRuntime();
|
|
26864
28733
|
if (!local)
|
|
26865
28734
|
throw new CliError(
|
|
@@ -26895,12 +28764,12 @@ Examples:
|
|
|
26895
28764
|
}
|
|
26896
28765
|
|
|
26897
28766
|
// src/cli/runtime/scaffold.ts
|
|
26898
|
-
var
|
|
28767
|
+
var fs56 = __toESM(require("fs"));
|
|
26899
28768
|
var path42 = __toESM(require("path"));
|
|
26900
28769
|
init_router();
|
|
26901
28770
|
|
|
26902
28771
|
// src/cli/runtime/scaffoldJson.ts
|
|
26903
|
-
var
|
|
28772
|
+
var fs55 = __toESM(require("fs"));
|
|
26904
28773
|
init_router();
|
|
26905
28774
|
var PROPERTY_NAME = /^[A-Za-z_][A-Za-z0-9_]*$/;
|
|
26906
28775
|
var isObject12 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
@@ -26915,10 +28784,10 @@ function resolveObjectSchema(root, schema) {
|
|
|
26915
28784
|
return schema;
|
|
26916
28785
|
}
|
|
26917
28786
|
function readJsonFile2(file) {
|
|
26918
|
-
if (!
|
|
28787
|
+
if (!fs55.existsSync(file)) throw new CliError(`${file} does not exist; run \`gateway worlds schema init\` first`, 1);
|
|
26919
28788
|
let parsed;
|
|
26920
28789
|
try {
|
|
26921
|
-
parsed = JSON.parse(
|
|
28790
|
+
parsed = JSON.parse(fs55.readFileSync(file, "utf8"));
|
|
26922
28791
|
} catch (err) {
|
|
26923
28792
|
throw new CliError(`${file} is not valid JSON: ${err.message}`, 1);
|
|
26924
28793
|
}
|
|
@@ -27149,7 +29018,7 @@ var MAX_ENTITY_NAME = 64;
|
|
|
27149
29018
|
var FIELD_TYPES = /* @__PURE__ */ new Set(["string", "integer", "number", "boolean"]);
|
|
27150
29019
|
function parseFields(spec) {
|
|
27151
29020
|
const properties = {};
|
|
27152
|
-
const
|
|
29021
|
+
const required2 = [];
|
|
27153
29022
|
for (const raw of spec.split(",")) {
|
|
27154
29023
|
const item = raw.trim();
|
|
27155
29024
|
if (!item) continue;
|
|
@@ -27167,10 +29036,10 @@ function parseFields(spec) {
|
|
|
27167
29036
|
);
|
|
27168
29037
|
if (name in properties) throw new CliError(`Duplicate field ${name}`);
|
|
27169
29038
|
properties[name] = { type };
|
|
27170
|
-
if (!optional)
|
|
29039
|
+
if (!optional) required2.push(name);
|
|
27171
29040
|
}
|
|
27172
29041
|
if (!Object.keys(properties).length) throw new CliError("--fields declares no properties");
|
|
27173
|
-
return { type: "object", properties, required, additionalProperties: false };
|
|
29042
|
+
return { type: "object", properties, required: required2, additionalProperties: false };
|
|
27174
29043
|
}
|
|
27175
29044
|
function parseRelationship(spec) {
|
|
27176
29045
|
const arrow = spec.indexOf("->");
|
|
@@ -27227,13 +29096,13 @@ function addEntity(root, spec) {
|
|
|
27227
29096
|
if (payload.type !== "object" || payload.additionalProperties !== false)
|
|
27228
29097
|
throw new CliError('An entity payload must be a closed object: type "object" with additionalProperties false');
|
|
27229
29098
|
const properties = isObject12(payload.properties) ? payload.properties : {};
|
|
27230
|
-
const
|
|
29099
|
+
const required2 = Array.isArray(payload.required) ? payload.required : [];
|
|
27231
29100
|
for (const key2 of spec.primaryKey) {
|
|
27232
29101
|
const prop = properties[key2];
|
|
27233
29102
|
if (!isObject12(prop)) throw new CliError(`Primary key field ${key2} is not a property of the payload`);
|
|
27234
29103
|
if (prop.type !== "string" && prop.type !== "integer")
|
|
27235
29104
|
throw new CliError(`Primary key field ${key2} must be a string or integer property`);
|
|
27236
|
-
if (!
|
|
29105
|
+
if (!required2.includes(key2)) throw new CliError(`Primary key field ${key2} must be required`);
|
|
27237
29106
|
}
|
|
27238
29107
|
for (const rel of spec.relationships)
|
|
27239
29108
|
for (const field2 of rel.fields)
|
|
@@ -27417,10 +29286,10 @@ function removeDependency(toml, alias) {
|
|
|
27417
29286
|
}
|
|
27418
29287
|
function dependencyServes(depDir) {
|
|
27419
29288
|
const manifest = path42.join(depDir, "gateway-env.toml");
|
|
27420
|
-
if (!
|
|
27421
|
-
const tools = manifestServedTools(
|
|
29289
|
+
if (!fs56.existsSync(manifest)) return void 0;
|
|
29290
|
+
const tools = manifestServedTools(fs56.readFileSync(manifest, "utf8"));
|
|
27422
29291
|
const connector = path42.join(depDir, "connector.toml");
|
|
27423
|
-
const routes =
|
|
29292
|
+
const routes = fs56.existsSync(connector) ? declaredRoutes(fs56.readFileSync(connector, "utf8")).map((r) => r.name).filter(Boolean) : [];
|
|
27424
29293
|
return tools === void 0 ? void 0 : { tools, routes };
|
|
27425
29294
|
}
|
|
27426
29295
|
function addDependency(toml, spec, depServes, opts = {}) {
|
|
@@ -27504,40 +29373,40 @@ function dependencyPath(toml, alias) {
|
|
|
27504
29373
|
}
|
|
27505
29374
|
function readManifest2(dir) {
|
|
27506
29375
|
const file = path42.join(dir, "gateway-env.toml");
|
|
27507
|
-
if (!
|
|
27508
|
-
return { file, toml:
|
|
29376
|
+
if (!fs56.existsSync(file)) throw new CliError(`${dir} holds no gateway-env.toml; run \`gateway worlds schema init\` first`, 1);
|
|
29377
|
+
return { file, toml: fs56.readFileSync(file, "utf8") };
|
|
27509
29378
|
}
|
|
27510
29379
|
function verifierNames2(dir) {
|
|
27511
29380
|
const folder = path42.join(dir, "verifiers");
|
|
27512
|
-
if (!
|
|
27513
|
-
return
|
|
29381
|
+
if (!fs56.existsSync(folder)) return void 0;
|
|
29382
|
+
return fs56.readdirSync(folder).filter((f) => f.endsWith(".sql")).map((f) => f.slice(0, -4)).sort();
|
|
27514
29383
|
}
|
|
27515
29384
|
var toPosix = (p) => p.split(path42.sep).join("/");
|
|
27516
29385
|
var pinSlug = (name) => name.toLowerCase().replace(/[^a-z0-9._-]+/g, "-").replace(/^[^a-z0-9]+/, "") || "world";
|
|
27517
29386
|
function declaredEntities(dir) {
|
|
27518
29387
|
const file = path42.join(dir, "schema", "world.json");
|
|
27519
|
-
if (!
|
|
29388
|
+
if (!fs56.existsSync(file)) return void 0;
|
|
27520
29389
|
const gateway = readJsonFile2(file)["x-gateway"];
|
|
27521
29390
|
return isObject12(gateway) && isObject12(gateway.entities) ? Object.keys(gateway.entities) : [];
|
|
27522
29391
|
}
|
|
27523
29392
|
function worldEntityShapes(dir) {
|
|
27524
29393
|
const file = path42.join(dir, "schema", "world.json");
|
|
27525
|
-
return
|
|
29394
|
+
return fs56.existsSync(file) ? declaredEntityShapes(readJsonFile2(file)) : void 0;
|
|
27526
29395
|
}
|
|
27527
29396
|
function declaredHandlerTools(dir) {
|
|
27528
29397
|
const file = path42.join(dir, "schema", "world.json");
|
|
27529
|
-
if (!
|
|
29398
|
+
if (!fs56.existsSync(file)) return [];
|
|
27530
29399
|
const gateway = readJsonFile2(file)["x-gateway"];
|
|
27531
29400
|
return isObject12(gateway) && isObject12(gateway.tools) ? Object.keys(gateway.tools) : [];
|
|
27532
29401
|
}
|
|
27533
29402
|
var WORLD_SLUG = /^[a-z0-9][a-z0-9-]*$/;
|
|
27534
29403
|
function connectorTomlSkeleton(dir) {
|
|
27535
29404
|
const manifest = path42.join(dir, "gateway-env.toml");
|
|
27536
|
-
if (!
|
|
29405
|
+
if (!fs56.existsSync(dir))
|
|
27537
29406
|
throw new CliError(`${dir} does not exist; run \`gateway worlds schema init ${dir} --connector custom\` to start a world there`, 1);
|
|
27538
|
-
if (!
|
|
29407
|
+
if (!fs56.existsSync(manifest))
|
|
27539
29408
|
throw new CliError(`${dir} holds no connector.toml and no gateway-env.toml (not a world); run \`gateway worlds schema init ${dir} --connector custom\` first`, 1);
|
|
27540
|
-
const name = /^\s*name\s*=\s*"([^"]*)"/m.exec(
|
|
29409
|
+
const name = /^\s*name\s*=\s*"([^"]*)"/m.exec(fs56.readFileSync(manifest, "utf8"))?.[1];
|
|
27541
29410
|
const slug = name && WORLD_SLUG.test(name) ? name : path42.basename(dir).toLowerCase().replace(/[^a-z0-9-]+/g, "-").replace(/^-+|-+$/g, "") || "world";
|
|
27542
29411
|
return [
|
|
27543
29412
|
`# ${slug}'s API surface: the HTTP routes the world serves beside its tools, from one`,
|
|
@@ -27594,20 +29463,20 @@ function whereClauseDefect(clause) {
|
|
|
27594
29463
|
function addVerifier(dir, name, entity, where) {
|
|
27595
29464
|
const sql = verifierSql(name, entity, where);
|
|
27596
29465
|
const file = path42.join(dir, "verifiers", `${name}.sql`);
|
|
27597
|
-
if (
|
|
29466
|
+
if (fs56.existsSync(file))
|
|
27598
29467
|
throw new CliError(`verifiers/${name}.sql already exists (have: ${(verifierNames2(dir) ?? []).join(", ")}); edit it, or pick another name`);
|
|
27599
|
-
|
|
27600
|
-
|
|
29468
|
+
fs56.mkdirSync(path42.dirname(file), { recursive: true });
|
|
29469
|
+
fs56.writeFileSync(file, sql);
|
|
27601
29470
|
return file;
|
|
27602
29471
|
}
|
|
27603
29472
|
function repointScaffoldVerifier(dir, entity, declared) {
|
|
27604
29473
|
const file = path42.join(dir, "verifiers", "state_present.sql");
|
|
27605
|
-
if (!
|
|
27606
|
-
const text2 =
|
|
29474
|
+
if (!fs56.existsSync(file)) return null;
|
|
29475
|
+
const text2 = fs56.readFileSync(file, "utf8");
|
|
27607
29476
|
const match = SCAFFOLD_VERIFIER.exec(text2);
|
|
27608
29477
|
if (!match || text2 !== scaffoldVerifier(match[1])) return null;
|
|
27609
29478
|
if (declared.includes(match[1])) return null;
|
|
27610
|
-
|
|
29479
|
+
fs56.writeFileSync(file, scaffoldVerifier(entity));
|
|
27611
29480
|
return file;
|
|
27612
29481
|
}
|
|
27613
29482
|
function parsePairs(values, flag) {
|
|
@@ -27670,7 +29539,7 @@ function registerScaffoldCommands(worlds) {
|
|
|
27670
29539
|
unique: arg.list(args, "unique").map((u) => u.split(",").map((f) => f.trim()).filter(Boolean)),
|
|
27671
29540
|
relationships: arg.list(args, "relationship").map(parseRelationship)
|
|
27672
29541
|
});
|
|
27673
|
-
|
|
29542
|
+
fs56.writeFileSync(file, JSON.stringify(document, null, 2) + "\n");
|
|
27674
29543
|
const out = { status: "ok", entity: name, declaration, file: path42.relative(process.cwd(), file) || file };
|
|
27675
29544
|
if (def) out.def = def;
|
|
27676
29545
|
const verifier = repointScaffoldVerifier(dir, name, declaredEntities(dir) ?? []);
|
|
@@ -27751,21 +29620,21 @@ function registerScaffoldCommands(worlds) {
|
|
|
27751
29620
|
const depArg = args.positionals[2];
|
|
27752
29621
|
const depDir = path42.resolve(depArg);
|
|
27753
29622
|
const { file, toml } = readManifest2(dir);
|
|
27754
|
-
if (!
|
|
29623
|
+
if (!fs56.existsSync(path42.join(depDir, "gateway-env.toml"))) {
|
|
27755
29624
|
const fromWorld = path42.resolve(dir, depArg);
|
|
27756
|
-
const hint = fromWorld !== depDir &&
|
|
29625
|
+
const hint = fromWorld !== depDir && fs56.existsSync(path42.join(fromWorld, "gateway-env.toml")) ? `; paths resolve from your shell, not from the world: did you mean ${path42.relative(process.cwd(), fromWorld) || "."}?` : "";
|
|
27757
29626
|
throw new CliError(
|
|
27758
29627
|
`${depDir} holds no gateway-env.toml; the dependency must be a schema world (\`gateway worlds schema init\`)${hint}`,
|
|
27759
29628
|
1
|
|
27760
29629
|
);
|
|
27761
29630
|
}
|
|
27762
29631
|
if (path42.resolve(depDir) === dir) throw new CliError("A world cannot depend on itself");
|
|
27763
|
-
const depToml =
|
|
29632
|
+
const depToml = fs56.readFileSync(path42.join(depDir, "gateway-env.toml"), "utf8");
|
|
27764
29633
|
if (declaredAliases(depToml).length)
|
|
27765
29634
|
throw new CliError(`${depDir} has [dependencies] of its own (${declaredAliases(depToml).join(", ")}); links nest one level`);
|
|
27766
29635
|
const task = arg.str(args, "task");
|
|
27767
|
-
if (task !== void 0 && !
|
|
27768
|
-
const have =
|
|
29636
|
+
if (task !== void 0 && !fs56.existsSync(path42.join(depDir, "scenarios", task))) {
|
|
29637
|
+
const have = fs56.existsSync(path42.join(depDir, "scenarios")) ? fs56.readdirSync(path42.join(depDir, "scenarios")) : [];
|
|
27769
29638
|
throw new CliError(`${depDir} has no scenarios/${task}/ (have: ${have.join(", ") || "none"})`);
|
|
27770
29639
|
}
|
|
27771
29640
|
const rel = toPosix(path42.relative(dir, depDir)) || ".";
|
|
@@ -27778,7 +29647,7 @@ function registerScaffoldCommands(worlds) {
|
|
|
27778
29647
|
entities: arg.list(args, "map").map(parseEntityMap)
|
|
27779
29648
|
};
|
|
27780
29649
|
const updated = addDependency(toml, spec, dependencyServes(depDir), { replace: arg.bool(args, "replace") });
|
|
27781
|
-
|
|
29650
|
+
fs56.writeFileSync(file, updated);
|
|
27782
29651
|
ctx.stdout(
|
|
27783
29652
|
JSON.stringify(
|
|
27784
29653
|
{
|
|
@@ -27851,7 +29720,7 @@ function registerScaffoldCommands(worlds) {
|
|
|
27851
29720
|
{ verifiers: verifierNames2(dir), depVerifiers },
|
|
27852
29721
|
{ replace: arg.bool(args, "replace") }
|
|
27853
29722
|
);
|
|
27854
|
-
|
|
29723
|
+
fs56.writeFileSync(file, updated);
|
|
27855
29724
|
ctx.stdout(
|
|
27856
29725
|
JSON.stringify(
|
|
27857
29726
|
{
|
|
@@ -27918,7 +29787,7 @@ function registerScaffoldCommands(worlds) {
|
|
|
27918
29787
|
run: async (args, ctx) => {
|
|
27919
29788
|
const dir = path42.resolve(args.positionals[0]);
|
|
27920
29789
|
const file = path42.join(dir, "connector.toml");
|
|
27921
|
-
const created = !
|
|
29790
|
+
const created = !fs56.existsSync(file);
|
|
27922
29791
|
const routePath = arg.str(args, "path");
|
|
27923
29792
|
if (routePath === void 0) throw new CliError("--path is required, e.g. --path /users");
|
|
27924
29793
|
const spec = {
|
|
@@ -27941,13 +29810,13 @@ function registerScaffoldCommands(worlds) {
|
|
|
27941
29810
|
}
|
|
27942
29811
|
};
|
|
27943
29812
|
const replace = arg.bool(args, "replace");
|
|
27944
|
-
const current = created ? connectorTomlSkeleton(dir) :
|
|
29813
|
+
const current = created ? connectorTomlSkeleton(dir) : fs56.readFileSync(file, "utf8");
|
|
27945
29814
|
const updated = addRoute(current, spec, declaredEntities(dir), {
|
|
27946
29815
|
replace,
|
|
27947
29816
|
handlerTools: declaredHandlerTools(dir),
|
|
27948
29817
|
entities: worldEntityShapes(dir)
|
|
27949
29818
|
});
|
|
27950
|
-
|
|
29819
|
+
fs56.writeFileSync(file, updated);
|
|
27951
29820
|
ctx.stdout(
|
|
27952
29821
|
JSON.stringify(
|
|
27953
29822
|
{
|
|
@@ -27993,13 +29862,13 @@ function registerRuntimeCommands(root) {
|
|
|
27993
29862
|
}
|
|
27994
29863
|
|
|
27995
29864
|
// src/cli/version.ts
|
|
27996
|
-
var
|
|
29865
|
+
var fs57 = __toESM(require("fs"));
|
|
27997
29866
|
var path43 = __toESM(require("path"));
|
|
27998
29867
|
function cliVersion() {
|
|
27999
|
-
if (true) return "0.
|
|
29868
|
+
if (true) return "0.3.0";
|
|
28000
29869
|
if (typeof __dirname !== "string") return "unknown";
|
|
28001
29870
|
try {
|
|
28002
|
-
const pkg = JSON.parse(
|
|
29871
|
+
const pkg = JSON.parse(fs57.readFileSync(path43.resolve(__dirname, "../../package.json"), "utf8"));
|
|
28003
29872
|
return pkg.version ?? "unknown";
|
|
28004
29873
|
} catch {
|
|
28005
29874
|
return "unknown";
|