@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/index.mjs
CHANGED
|
@@ -742,7 +742,7 @@ function withoutUiToken(url) {
|
|
|
742
742
|
const [beforeHash, hash] = splitHash(url);
|
|
743
743
|
const q = beforeHash.indexOf("?");
|
|
744
744
|
if (q < 0) return url;
|
|
745
|
-
const kept = beforeHash.slice(q + 1).split("&").filter((
|
|
745
|
+
const kept = beforeHash.slice(q + 1).split("&").filter((pair3) => pair3 !== "" && pair3.split("=")[0] !== UI_TOKEN_QUERY);
|
|
746
746
|
return beforeHash.slice(0, q) + (kept.length ? `?${kept.join("&")}` : "") + hash;
|
|
747
747
|
}
|
|
748
748
|
function splitHash(url) {
|
|
@@ -877,7 +877,7 @@ var SURFACE_KINDS, BROWSER_TIERS, DEFAULT_VIEWPORT, SETTLE_TIMEOUT_MS, SETTLE_QU
|
|
|
877
877
|
var init_browser = __esm({
|
|
878
878
|
"src/worlds/browser.ts"() {
|
|
879
879
|
"use strict";
|
|
880
|
-
|
|
880
|
+
init_session2();
|
|
881
881
|
init_browserReconnect();
|
|
882
882
|
SURFACE_KINDS = ["tools", "api", "ui", "browser"];
|
|
883
883
|
BROWSER_TIERS = ["standard", "premium"];
|
|
@@ -1023,6 +1023,10 @@ var init_browser = __esm({
|
|
|
1023
1023
|
get agentId() {
|
|
1024
1024
|
return this.recorder?.agentId ?? null;
|
|
1025
1025
|
}
|
|
1026
|
+
/** `text` with this session's credentials (UI token, browser address) removed. */
|
|
1027
|
+
scrub(text2) {
|
|
1028
|
+
return this.scrubber.scrub(text2);
|
|
1029
|
+
}
|
|
1026
1030
|
watchNetwork(page) {
|
|
1027
1031
|
page.on("request", () => {
|
|
1028
1032
|
this.inflight += 1;
|
|
@@ -1309,6 +1313,1269 @@ var init_browser = __esm({
|
|
|
1309
1313
|
}
|
|
1310
1314
|
});
|
|
1311
1315
|
|
|
1316
|
+
// src/worlds/nativeComputer/actions.ts
|
|
1317
|
+
function toNumber(value) {
|
|
1318
|
+
if (typeof value !== "number" || !Number.isFinite(value))
|
|
1319
|
+
throw new Error(`not a number: ${JSON.stringify(value) ?? String(value)}`);
|
|
1320
|
+
return value;
|
|
1321
|
+
}
|
|
1322
|
+
function toInt(value) {
|
|
1323
|
+
return Math.trunc(toNumber(value));
|
|
1324
|
+
}
|
|
1325
|
+
var ACTION_NAMES, SECRET_TEXT, BOUNDS, ComputerAction;
|
|
1326
|
+
var init_actions = __esm({
|
|
1327
|
+
"src/worlds/nativeComputer/actions.ts"() {
|
|
1328
|
+
"use strict";
|
|
1329
|
+
ACTION_NAMES = [
|
|
1330
|
+
"screenshot",
|
|
1331
|
+
"zoom",
|
|
1332
|
+
"click",
|
|
1333
|
+
"move",
|
|
1334
|
+
"mouse_down",
|
|
1335
|
+
"mouse_up",
|
|
1336
|
+
"drag",
|
|
1337
|
+
"scroll",
|
|
1338
|
+
"type",
|
|
1339
|
+
"key",
|
|
1340
|
+
"hold_key",
|
|
1341
|
+
"wait",
|
|
1342
|
+
"cursor_position",
|
|
1343
|
+
"history"
|
|
1344
|
+
];
|
|
1345
|
+
SECRET_TEXT = "[redacted]";
|
|
1346
|
+
BOUNDS = {
|
|
1347
|
+
seconds: [0, 300],
|
|
1348
|
+
repeat: [1, 100],
|
|
1349
|
+
count: [1, 3],
|
|
1350
|
+
dx: [-1e4, 1e4],
|
|
1351
|
+
dy: [-1e4, 1e4]
|
|
1352
|
+
};
|
|
1353
|
+
ComputerAction = class {
|
|
1354
|
+
constructor(name, args = {}) {
|
|
1355
|
+
this.name = name;
|
|
1356
|
+
this.args = args;
|
|
1357
|
+
if (!ACTION_NAMES.includes(name))
|
|
1358
|
+
throw new Error(`unknown computer action: ${name}`);
|
|
1359
|
+
for (const [key2, [low, high]] of Object.entries(BOUNDS)) {
|
|
1360
|
+
const value = args[key2];
|
|
1361
|
+
if (value !== void 0 && !(Number(value) >= low && Number(value) <= high))
|
|
1362
|
+
throw new Error(
|
|
1363
|
+
`${name} ${key2} must be between ${low} and ${high}, got ${String(value)}`
|
|
1364
|
+
);
|
|
1365
|
+
}
|
|
1366
|
+
}
|
|
1367
|
+
name;
|
|
1368
|
+
args;
|
|
1369
|
+
/** Flat arguments for the browser timeline and the trace: lists become
|
|
1370
|
+
* `"x,y"` strings, and typed text is withheld when it went into a
|
|
1371
|
+
* credential field. */
|
|
1372
|
+
recordArgs(secretText) {
|
|
1373
|
+
const out = {};
|
|
1374
|
+
for (const [key2, value] of Object.entries(this.args))
|
|
1375
|
+
out[key2] = Array.isArray(value) ? value.flat().join(",") : value;
|
|
1376
|
+
if (secretText && "text" in out) out.text = SECRET_TEXT;
|
|
1377
|
+
return out;
|
|
1378
|
+
}
|
|
1379
|
+
};
|
|
1380
|
+
}
|
|
1381
|
+
});
|
|
1382
|
+
|
|
1383
|
+
// src/worlds/nativeComputer/display.ts
|
|
1384
|
+
var FIT_STEP, Display;
|
|
1385
|
+
var init_display = __esm({
|
|
1386
|
+
"src/worlds/nativeComputer/display.ts"() {
|
|
1387
|
+
"use strict";
|
|
1388
|
+
FIT_STEP = 0.98;
|
|
1389
|
+
Display = class _Display {
|
|
1390
|
+
constructor(width, height, viewportWidth, viewportHeight) {
|
|
1391
|
+
this.width = width;
|
|
1392
|
+
this.height = height;
|
|
1393
|
+
this.viewportWidth = viewportWidth;
|
|
1394
|
+
this.viewportHeight = viewportHeight;
|
|
1395
|
+
}
|
|
1396
|
+
width;
|
|
1397
|
+
height;
|
|
1398
|
+
viewportWidth;
|
|
1399
|
+
viewportHeight;
|
|
1400
|
+
/** `size` when the caller names one; otherwise the largest downscale of the
|
|
1401
|
+
* viewport (at most 1:1) that `fits` the provider's limits. */
|
|
1402
|
+
static forViewport(viewport, size, fits = () => true) {
|
|
1403
|
+
const { width, height } = viewport;
|
|
1404
|
+
if (size) return _Display.sized(size[0], size[1], width, height);
|
|
1405
|
+
let scale = 1;
|
|
1406
|
+
while (!fits(Math.round(width * scale), Math.round(height * scale)))
|
|
1407
|
+
scale *= FIT_STEP;
|
|
1408
|
+
return new _Display(
|
|
1409
|
+
Math.round(width * scale),
|
|
1410
|
+
Math.round(height * scale),
|
|
1411
|
+
width,
|
|
1412
|
+
height
|
|
1413
|
+
);
|
|
1414
|
+
}
|
|
1415
|
+
/** A caller's display keeps the viewport's shape: screenshots are scaled
|
|
1416
|
+
* uniformly, so another aspect ratio would map clicks off the image. */
|
|
1417
|
+
static sized(width, height, viewportWidth, viewportHeight) {
|
|
1418
|
+
if (width <= 0 || height <= 0)
|
|
1419
|
+
throw new Error(`display ${width}x${height} must be positive`);
|
|
1420
|
+
const sameShape = width * viewportHeight / viewportWidth;
|
|
1421
|
+
if (Math.abs(sameShape - height) > 1)
|
|
1422
|
+
throw new Error(
|
|
1423
|
+
`display ${width}x${height} must keep the viewport's aspect ratio (${viewportWidth}x${viewportHeight}); try ${width}x${Math.round(sameShape)}`
|
|
1424
|
+
);
|
|
1425
|
+
return new _Display(width, height, viewportWidth, viewportHeight);
|
|
1426
|
+
}
|
|
1427
|
+
get scaled() {
|
|
1428
|
+
return this.width !== this.viewportWidth || this.height !== this.viewportHeight;
|
|
1429
|
+
}
|
|
1430
|
+
get scale() {
|
|
1431
|
+
return Math.min(
|
|
1432
|
+
this.width / this.viewportWidth,
|
|
1433
|
+
this.height / this.viewportHeight
|
|
1434
|
+
);
|
|
1435
|
+
}
|
|
1436
|
+
toPage(x, y) {
|
|
1437
|
+
return [
|
|
1438
|
+
x * this.viewportWidth / this.width,
|
|
1439
|
+
y * this.viewportHeight / this.height
|
|
1440
|
+
];
|
|
1441
|
+
}
|
|
1442
|
+
};
|
|
1443
|
+
}
|
|
1444
|
+
});
|
|
1445
|
+
|
|
1446
|
+
// src/worlds/nativeComputer/screen.ts
|
|
1447
|
+
function pngWidth(png) {
|
|
1448
|
+
if (png.length < 24 || !png.subarray(0, 8).equals(PNG_SIGNATURE)) return null;
|
|
1449
|
+
return png.readUInt32BE(16);
|
|
1450
|
+
}
|
|
1451
|
+
function isNativePage(page) {
|
|
1452
|
+
const candidate = page;
|
|
1453
|
+
const mouse = candidate?.mouse;
|
|
1454
|
+
return typeof candidate?.context === "function" && NATIVE_METHODS.every((m) => typeof mouse?.[m] === "function");
|
|
1455
|
+
}
|
|
1456
|
+
var FOCUSED_FIELD_JS, SECRET_FOCUS, DRAG_STEPS, PNG_SIGNATURE, NATIVE_METHODS, Screen;
|
|
1457
|
+
var init_screen = __esm({
|
|
1458
|
+
"src/worlds/nativeComputer/screen.ts"() {
|
|
1459
|
+
"use strict";
|
|
1460
|
+
init_browser();
|
|
1461
|
+
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(' '); })()";
|
|
1462
|
+
SECRET_FOCUS = ["password", "frame", "opaque"];
|
|
1463
|
+
DRAG_STEPS = 5;
|
|
1464
|
+
PNG_SIGNATURE = Buffer.from([
|
|
1465
|
+
137,
|
|
1466
|
+
80,
|
|
1467
|
+
78,
|
|
1468
|
+
71,
|
|
1469
|
+
13,
|
|
1470
|
+
10,
|
|
1471
|
+
26,
|
|
1472
|
+
10
|
|
1473
|
+
]);
|
|
1474
|
+
NATIVE_METHODS = ["move", "click", "down", "up", "wheel"];
|
|
1475
|
+
Screen = class {
|
|
1476
|
+
constructor(browser, display) {
|
|
1477
|
+
this.browser = browser;
|
|
1478
|
+
this.display = display;
|
|
1479
|
+
}
|
|
1480
|
+
browser;
|
|
1481
|
+
display;
|
|
1482
|
+
cursor = [0, 0];
|
|
1483
|
+
pixelRatio = 1;
|
|
1484
|
+
handlers = {
|
|
1485
|
+
screenshot: async () => ({ image: await this.screenshot() }),
|
|
1486
|
+
zoom: (a) => this.zoom(a),
|
|
1487
|
+
click: (a) => this.click(a),
|
|
1488
|
+
move: (a) => this.held(a.args.modifiers ?? [], () => this.moveTo(this.point(a))),
|
|
1489
|
+
mouse_down: async (a) => {
|
|
1490
|
+
await this.page.mouse.down({ button: a.args.button ?? "left" });
|
|
1491
|
+
return {};
|
|
1492
|
+
},
|
|
1493
|
+
mouse_up: async (a) => {
|
|
1494
|
+
await this.page.mouse.up({ button: a.args.button ?? "left" });
|
|
1495
|
+
return {};
|
|
1496
|
+
},
|
|
1497
|
+
drag: (a) => this.drag(a),
|
|
1498
|
+
scroll: (a) => this.scroll(a),
|
|
1499
|
+
type: async (a) => {
|
|
1500
|
+
await this.page.keyboard.type(a.args.text ?? "");
|
|
1501
|
+
return {};
|
|
1502
|
+
},
|
|
1503
|
+
key: (a) => this.key(a),
|
|
1504
|
+
hold_key: (a) => this.held(
|
|
1505
|
+
a.args.keys ?? [],
|
|
1506
|
+
() => this.page.waitForTimeout((a.args.seconds ?? 0) * 1e3)
|
|
1507
|
+
),
|
|
1508
|
+
wait: async (a) => {
|
|
1509
|
+
await this.page.waitForTimeout((a.args.seconds ?? 0) * 1e3);
|
|
1510
|
+
return {};
|
|
1511
|
+
},
|
|
1512
|
+
cursor_position: async () => ({
|
|
1513
|
+
text: `X=${this.cursor[0]}, Y=${this.cursor[1]}`
|
|
1514
|
+
}),
|
|
1515
|
+
history: async (a) => {
|
|
1516
|
+
const navigate = {
|
|
1517
|
+
back: () => this.page.goBack(),
|
|
1518
|
+
forward: () => this.page.goForward()
|
|
1519
|
+
};
|
|
1520
|
+
await navigate[a.args.direction ?? "back"]();
|
|
1521
|
+
return {};
|
|
1522
|
+
}
|
|
1523
|
+
};
|
|
1524
|
+
/** The live page (a new object after a reconnect), as pixel-level Playwright. */
|
|
1525
|
+
get page() {
|
|
1526
|
+
const page = this.browser.page;
|
|
1527
|
+
if (!isNativePage(page))
|
|
1528
|
+
throw new Error(
|
|
1529
|
+
"native computer use needs a Playwright page (mouse.move/click/down/up/wheel, context())"
|
|
1530
|
+
);
|
|
1531
|
+
return page;
|
|
1532
|
+
}
|
|
1533
|
+
run(action) {
|
|
1534
|
+
return this.handlers[action.name](action);
|
|
1535
|
+
}
|
|
1536
|
+
/** A PNG of the viewport at the model's display size. */
|
|
1537
|
+
async screenshot() {
|
|
1538
|
+
if (!this.display.scaled) return this.page.screenshot({ type: "png" });
|
|
1539
|
+
const { viewportWidth: width, viewportHeight: height } = this.display;
|
|
1540
|
+
return this.capture({ x: 0, y: 0, width, height }, this.display.scale);
|
|
1541
|
+
}
|
|
1542
|
+
/** Whether keystrokes go to a credential field (a password input, or one
|
|
1543
|
+
* named like a token, key or PIN), looking through shadow roots and
|
|
1544
|
+
* same-origin frames. An unreadable page, a cross-origin frame or a focus
|
|
1545
|
+
* that is not a text field (a closed shadow root's host) counts as one. */
|
|
1546
|
+
async focusedFieldIsSecret() {
|
|
1547
|
+
let described;
|
|
1548
|
+
try {
|
|
1549
|
+
described = String(await this.page.evaluate(FOCUSED_FIELD_JS) ?? "");
|
|
1550
|
+
} catch {
|
|
1551
|
+
return true;
|
|
1552
|
+
}
|
|
1553
|
+
return SECRET_FOCUS.some((prefix) => described.startsWith(prefix)) || SECRET_KEY.test(described);
|
|
1554
|
+
}
|
|
1555
|
+
/** CDP renders a clip at the page's device pixel ratio as well as its
|
|
1556
|
+
* `scale` (a Retina host doubles it), so a capture of the wrong width
|
|
1557
|
+
* measures that ratio and is taken once more, corrected. */
|
|
1558
|
+
async capture(clip, scale) {
|
|
1559
|
+
const wanted = Math.round(clip.width * scale);
|
|
1560
|
+
const png = await this.cdpCapture(clip, scale / this.pixelRatio);
|
|
1561
|
+
const width = pngWidth(png);
|
|
1562
|
+
if (width === null || Math.abs(width - wanted) <= 1) return png;
|
|
1563
|
+
this.pixelRatio *= width / wanted;
|
|
1564
|
+
return this.cdpCapture(clip, scale / this.pixelRatio);
|
|
1565
|
+
}
|
|
1566
|
+
async cdpCapture(clip, scale) {
|
|
1567
|
+
const page = this.page;
|
|
1568
|
+
const session = await page.context().newCDPSession(page);
|
|
1569
|
+
try {
|
|
1570
|
+
const shot = await session.send("Page.captureScreenshot", {
|
|
1571
|
+
format: "png",
|
|
1572
|
+
clip: { ...clip, scale }
|
|
1573
|
+
});
|
|
1574
|
+
return Buffer.from(shot.data, "base64");
|
|
1575
|
+
} finally {
|
|
1576
|
+
await session.detach();
|
|
1577
|
+
}
|
|
1578
|
+
}
|
|
1579
|
+
point(action) {
|
|
1580
|
+
const { x, y } = action.args;
|
|
1581
|
+
return x === void 0 || y === void 0 ? this.cursor : [x, y];
|
|
1582
|
+
}
|
|
1583
|
+
async moveTo(point2, steps = 1) {
|
|
1584
|
+
const [x, y] = this.display.toPage(point2[0], point2[1]);
|
|
1585
|
+
await this.page.mouse.move(x, y, { steps });
|
|
1586
|
+
this.cursor = point2;
|
|
1587
|
+
}
|
|
1588
|
+
async held(modifiers, fn) {
|
|
1589
|
+
for (const key2 of modifiers) await this.page.keyboard.down(key2);
|
|
1590
|
+
try {
|
|
1591
|
+
await fn();
|
|
1592
|
+
} finally {
|
|
1593
|
+
for (const key2 of [...modifiers].reverse())
|
|
1594
|
+
await this.page.keyboard.up(key2);
|
|
1595
|
+
}
|
|
1596
|
+
return {};
|
|
1597
|
+
}
|
|
1598
|
+
async zoom(action) {
|
|
1599
|
+
const [x0, y0, x1, y1] = action.args.region ?? [0, 0, 0, 0];
|
|
1600
|
+
const [left, top] = this.display.toPage(x0, y0);
|
|
1601
|
+
const [right, bottom] = this.display.toPage(x1, y1);
|
|
1602
|
+
if (right <= left || bottom <= top)
|
|
1603
|
+
throw new Error("zoom region must have x1 > x0 and y1 > y0");
|
|
1604
|
+
const width = right - left;
|
|
1605
|
+
const height = bottom - top;
|
|
1606
|
+
const scale = Math.min(
|
|
1607
|
+
this.display.width / width,
|
|
1608
|
+
this.display.height / height
|
|
1609
|
+
);
|
|
1610
|
+
return {
|
|
1611
|
+
image: await this.capture({ x: left, y: top, width, height }, scale)
|
|
1612
|
+
};
|
|
1613
|
+
}
|
|
1614
|
+
async click(action) {
|
|
1615
|
+
const point2 = this.point(action);
|
|
1616
|
+
return this.held(action.args.modifiers ?? [], async () => {
|
|
1617
|
+
await this.moveTo(point2);
|
|
1618
|
+
const [x, y] = this.display.toPage(point2[0], point2[1]);
|
|
1619
|
+
await this.page.mouse.click(x, y, {
|
|
1620
|
+
button: action.args.button ?? "left",
|
|
1621
|
+
clickCount: action.args.count ?? 1
|
|
1622
|
+
});
|
|
1623
|
+
});
|
|
1624
|
+
}
|
|
1625
|
+
async drag(action) {
|
|
1626
|
+
const path16 = action.args.path ?? [];
|
|
1627
|
+
if (path16.length < 2) throw new Error("a drag needs at least two points");
|
|
1628
|
+
return this.held(action.args.modifiers ?? [], async () => {
|
|
1629
|
+
await this.moveTo(path16[0]);
|
|
1630
|
+
await this.page.mouse.down({ button: "left" });
|
|
1631
|
+
try {
|
|
1632
|
+
for (const point2 of path16.slice(1)) await this.moveTo(point2, DRAG_STEPS);
|
|
1633
|
+
} finally {
|
|
1634
|
+
await this.page.mouse.up({ button: "left" });
|
|
1635
|
+
}
|
|
1636
|
+
});
|
|
1637
|
+
}
|
|
1638
|
+
async scroll(action) {
|
|
1639
|
+
await this.moveTo(this.point(action));
|
|
1640
|
+
const scale = this.display.scale;
|
|
1641
|
+
return this.held(
|
|
1642
|
+
action.args.modifiers ?? [],
|
|
1643
|
+
() => this.page.mouse.wheel(
|
|
1644
|
+
(action.args.dx ?? 0) / scale,
|
|
1645
|
+
(action.args.dy ?? 0) / scale
|
|
1646
|
+
)
|
|
1647
|
+
);
|
|
1648
|
+
}
|
|
1649
|
+
async key(action) {
|
|
1650
|
+
const combo = (action.args.keys ?? []).join("+");
|
|
1651
|
+
for (let i = 0; i < (action.args.repeat ?? 1); i += 1)
|
|
1652
|
+
await this.page.keyboard.press(combo);
|
|
1653
|
+
return {};
|
|
1654
|
+
}
|
|
1655
|
+
};
|
|
1656
|
+
}
|
|
1657
|
+
});
|
|
1658
|
+
|
|
1659
|
+
// src/tracing/media.ts
|
|
1660
|
+
import { createHash as createHash2 } from "crypto";
|
|
1661
|
+
async function putBytes(url, data, headers) {
|
|
1662
|
+
const controller = new AbortController();
|
|
1663
|
+
const timer = setTimeout(() => controller.abort(), PUT_TIMEOUT_MS);
|
|
1664
|
+
try {
|
|
1665
|
+
const res = await fetch(url, {
|
|
1666
|
+
method: "PUT",
|
|
1667
|
+
body: new Uint8Array(data),
|
|
1668
|
+
headers,
|
|
1669
|
+
signal: controller.signal
|
|
1670
|
+
});
|
|
1671
|
+
return {
|
|
1672
|
+
status: res.status,
|
|
1673
|
+
error: res.ok ? null : (await res.text()).slice(0, MAX_UPLOAD_ERROR)
|
|
1674
|
+
};
|
|
1675
|
+
} catch (error) {
|
|
1676
|
+
return {
|
|
1677
|
+
status: NETWORK_FAILURE_STATUS,
|
|
1678
|
+
error: error instanceof Error ? error.name : "Error"
|
|
1679
|
+
};
|
|
1680
|
+
} finally {
|
|
1681
|
+
clearTimeout(timer);
|
|
1682
|
+
}
|
|
1683
|
+
}
|
|
1684
|
+
var MEDIA_PATH, MAX_MEDIA_BYTES, PUT_TIMEOUT_MS, MAX_UPLOAD_ERROR, NETWORK_FAILURE_STATUS, MediaUploadError, MediaReference, MediaUploader;
|
|
1685
|
+
var init_media = __esm({
|
|
1686
|
+
"src/tracing/media.ts"() {
|
|
1687
|
+
"use strict";
|
|
1688
|
+
init_transport();
|
|
1689
|
+
MEDIA_PATH = "/api/public/media";
|
|
1690
|
+
MAX_MEDIA_BYTES = 5 * 1024 * 1024;
|
|
1691
|
+
PUT_TIMEOUT_MS = 3e4;
|
|
1692
|
+
MAX_UPLOAD_ERROR = 500;
|
|
1693
|
+
NETWORK_FAILURE_STATUS = 599;
|
|
1694
|
+
MediaUploadError = class extends Error {
|
|
1695
|
+
constructor(message, status) {
|
|
1696
|
+
super(message);
|
|
1697
|
+
this.status = status;
|
|
1698
|
+
this.name = "MediaUploadError";
|
|
1699
|
+
}
|
|
1700
|
+
status;
|
|
1701
|
+
};
|
|
1702
|
+
MediaReference = class {
|
|
1703
|
+
constructor(mediaId, contentType) {
|
|
1704
|
+
this.mediaId = mediaId;
|
|
1705
|
+
this.contentType = contentType;
|
|
1706
|
+
}
|
|
1707
|
+
mediaId;
|
|
1708
|
+
contentType;
|
|
1709
|
+
toString() {
|
|
1710
|
+
return `@@@langfuseMedia:type=${this.contentType}|id=${this.mediaId}|source=bytes@@@`;
|
|
1711
|
+
}
|
|
1712
|
+
};
|
|
1713
|
+
MediaUploader = class _MediaUploader {
|
|
1714
|
+
constructor(transport, put = putBytes, maxBytes = MAX_MEDIA_BYTES) {
|
|
1715
|
+
this.transport = transport;
|
|
1716
|
+
this.put = put;
|
|
1717
|
+
this.maxBytes = maxBytes;
|
|
1718
|
+
}
|
|
1719
|
+
transport;
|
|
1720
|
+
put;
|
|
1721
|
+
maxBytes;
|
|
1722
|
+
/** The uploader for `GATEWAY_HOST` / `GATEWAY_PUBLIC_KEY` /
|
|
1723
|
+
* `GATEWAY_SECRET_KEY` (the keys tracing exports with); null when any is unset. */
|
|
1724
|
+
static fromEnv(env = process.env) {
|
|
1725
|
+
const host = env.GATEWAY_HOST;
|
|
1726
|
+
const publicKey = env.GATEWAY_PUBLIC_KEY;
|
|
1727
|
+
const secretKey = env.GATEWAY_SECRET_KEY;
|
|
1728
|
+
if (!host || !publicKey || !secretKey) return null;
|
|
1729
|
+
return new _MediaUploader(
|
|
1730
|
+
new PlatformTransport({
|
|
1731
|
+
host: host.replace(/\/$/, ""),
|
|
1732
|
+
publicKey,
|
|
1733
|
+
secretKey
|
|
1734
|
+
})
|
|
1735
|
+
);
|
|
1736
|
+
}
|
|
1737
|
+
/** Store `data` linked to the trace (and observation) and return its reference. */
|
|
1738
|
+
async upload(data, link) {
|
|
1739
|
+
if (data.length > this.maxBytes)
|
|
1740
|
+
throw new MediaUploadError(
|
|
1741
|
+
`media is ${data.length} bytes, over the ${this.maxBytes}-byte cap`
|
|
1742
|
+
);
|
|
1743
|
+
const sha256Hash = createHash2("sha256").update(data).digest("base64");
|
|
1744
|
+
const answer = await this.send("POST", MEDIA_PATH, {
|
|
1745
|
+
traceId: link.traceId,
|
|
1746
|
+
observationId: link.observationId,
|
|
1747
|
+
contentType: link.contentType,
|
|
1748
|
+
contentLength: data.length,
|
|
1749
|
+
sha256Hash,
|
|
1750
|
+
field: link.field
|
|
1751
|
+
});
|
|
1752
|
+
if (typeof answer.mediaId !== "string" || !answer.mediaId)
|
|
1753
|
+
throw new MediaUploadError(
|
|
1754
|
+
"POST /api/public/media answered without a mediaId"
|
|
1755
|
+
);
|
|
1756
|
+
const reference = new MediaReference(answer.mediaId, link.contentType);
|
|
1757
|
+
if (answer.uploadUrl)
|
|
1758
|
+
await this.store(reference, answer.uploadUrl, data, sha256Hash);
|
|
1759
|
+
return reference;
|
|
1760
|
+
}
|
|
1761
|
+
async store(reference, url, data, sha256Hash) {
|
|
1762
|
+
const started = Date.now();
|
|
1763
|
+
const { status, error } = await this.put(url, data, {
|
|
1764
|
+
"Content-Type": reference.contentType,
|
|
1765
|
+
"x-amz-checksum-sha256": sha256Hash,
|
|
1766
|
+
"x-ms-blob-type": "BlockBlob"
|
|
1767
|
+
});
|
|
1768
|
+
await this.send(
|
|
1769
|
+
"PATCH",
|
|
1770
|
+
`${MEDIA_PATH}/${encodeURIComponent(reference.mediaId)}`,
|
|
1771
|
+
{
|
|
1772
|
+
uploadedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1773
|
+
uploadHttpStatus: status,
|
|
1774
|
+
uploadHttpError: error,
|
|
1775
|
+
uploadTimeMs: Date.now() - started
|
|
1776
|
+
}
|
|
1777
|
+
);
|
|
1778
|
+
if (status < 200 || status >= 300)
|
|
1779
|
+
throw new MediaUploadError(
|
|
1780
|
+
`media storage refused the upload (HTTP ${status})`,
|
|
1781
|
+
status
|
|
1782
|
+
);
|
|
1783
|
+
}
|
|
1784
|
+
async send(method, route, body) {
|
|
1785
|
+
const reply = await this.transport.send(method, route, body);
|
|
1786
|
+
if (!reply.ok)
|
|
1787
|
+
throw new MediaUploadError(
|
|
1788
|
+
`${method} ${route} -> ${reply.status}`,
|
|
1789
|
+
reply.status
|
|
1790
|
+
);
|
|
1791
|
+
return reply.text ? JSON.parse(reply.text) : {};
|
|
1792
|
+
}
|
|
1793
|
+
};
|
|
1794
|
+
}
|
|
1795
|
+
});
|
|
1796
|
+
|
|
1797
|
+
// src/worlds/nativeComputer/trace.ts
|
|
1798
|
+
function loadOtelApi() {
|
|
1799
|
+
if (otelApi !== void 0) return otelApi;
|
|
1800
|
+
try {
|
|
1801
|
+
otelApi = __require("@opentelemetry/api");
|
|
1802
|
+
} catch {
|
|
1803
|
+
otelApi = null;
|
|
1804
|
+
}
|
|
1805
|
+
return otelApi;
|
|
1806
|
+
}
|
|
1807
|
+
function errorText(error) {
|
|
1808
|
+
return error instanceof Error ? `${error.name}: ${error.message}` : String(error);
|
|
1809
|
+
}
|
|
1810
|
+
function errorName(error) {
|
|
1811
|
+
return error instanceof Error ? error.name : "Error";
|
|
1812
|
+
}
|
|
1813
|
+
var SPAN_PREFIX, MAX_UPLOAD_FAILURES, TRACER_NAME, MAX_ERROR, otelApi, ActionTracer;
|
|
1814
|
+
var init_trace = __esm({
|
|
1815
|
+
"src/worlds/nativeComputer/trace.ts"() {
|
|
1816
|
+
"use strict";
|
|
1817
|
+
init_media();
|
|
1818
|
+
SPAN_PREFIX = "computer.";
|
|
1819
|
+
MAX_UPLOAD_FAILURES = 3;
|
|
1820
|
+
TRACER_NAME = "@withgateway/sdk";
|
|
1821
|
+
MAX_ERROR = 1e3;
|
|
1822
|
+
ActionTracer = class _ActionTracer {
|
|
1823
|
+
constructor(media, warn3 = (m) => console.warn(m)) {
|
|
1824
|
+
this.media = media;
|
|
1825
|
+
this.warn = warn3;
|
|
1826
|
+
}
|
|
1827
|
+
media;
|
|
1828
|
+
warn;
|
|
1829
|
+
failures = 0;
|
|
1830
|
+
warned = false;
|
|
1831
|
+
static fromEnv() {
|
|
1832
|
+
return new _ActionTracer(MediaUploader.fromEnv());
|
|
1833
|
+
}
|
|
1834
|
+
/** `args` are already redacted. A failure's status goes through `scrub`:
|
|
1835
|
+
* browser errors quote the session's ws URL and UI token. */
|
|
1836
|
+
async span(action, args, run, capture, scrub) {
|
|
1837
|
+
const otel = loadOtelApi();
|
|
1838
|
+
if (!otel) return run();
|
|
1839
|
+
const { SpanStatusCode: SpanStatusCode3, trace: trace5 } = otel;
|
|
1840
|
+
const attributes = {
|
|
1841
|
+
"gateway.observation.type": "tool",
|
|
1842
|
+
"tool.name": SPAN_PREFIX + action.name,
|
|
1843
|
+
"gateway.observation.input": JSON.stringify({
|
|
1844
|
+
action: action.name,
|
|
1845
|
+
...args
|
|
1846
|
+
})
|
|
1847
|
+
};
|
|
1848
|
+
return trace5.getTracer(TRACER_NAME).startActiveSpan(
|
|
1849
|
+
SPAN_PREFIX + action.name,
|
|
1850
|
+
{ attributes },
|
|
1851
|
+
async (span) => {
|
|
1852
|
+
try {
|
|
1853
|
+
const result = await run();
|
|
1854
|
+
await this.finish(span, result, capture);
|
|
1855
|
+
span.setStatus({ code: SpanStatusCode3.OK });
|
|
1856
|
+
return result;
|
|
1857
|
+
} catch (error) {
|
|
1858
|
+
span.setStatus({
|
|
1859
|
+
code: SpanStatusCode3.ERROR,
|
|
1860
|
+
message: scrub(errorText(error)).slice(0, MAX_ERROR)
|
|
1861
|
+
});
|
|
1862
|
+
throw error;
|
|
1863
|
+
} finally {
|
|
1864
|
+
span.end();
|
|
1865
|
+
}
|
|
1866
|
+
}
|
|
1867
|
+
);
|
|
1868
|
+
}
|
|
1869
|
+
async finish(span, result, capture) {
|
|
1870
|
+
if (!span.isRecording()) return;
|
|
1871
|
+
const output = {
|
|
1872
|
+
screenshot: await this.screenshot(span, result, capture)
|
|
1873
|
+
};
|
|
1874
|
+
if (result.text !== void 0) output.text = result.text;
|
|
1875
|
+
span.setAttribute("gateway.observation.output", JSON.stringify(output));
|
|
1876
|
+
}
|
|
1877
|
+
async screenshot(span, result, capture) {
|
|
1878
|
+
let png;
|
|
1879
|
+
try {
|
|
1880
|
+
png = result.image ?? await capture();
|
|
1881
|
+
} catch (error) {
|
|
1882
|
+
return `[screenshot unavailable: ${errorName(error)}]`;
|
|
1883
|
+
}
|
|
1884
|
+
return this.reference(png, span);
|
|
1885
|
+
}
|
|
1886
|
+
async reference(png, span) {
|
|
1887
|
+
if (!this.media)
|
|
1888
|
+
return "[screenshot not uploaded: GATEWAY_HOST / GATEWAY_PUBLIC_KEY / GATEWAY_SECRET_KEY unset]";
|
|
1889
|
+
if (this.failures >= MAX_UPLOAD_FAILURES)
|
|
1890
|
+
return "[screenshot not uploaded: uploads disabled after repeated failures]";
|
|
1891
|
+
const { traceId, spanId } = span.spanContext();
|
|
1892
|
+
try {
|
|
1893
|
+
const reference = await this.media.upload(png, {
|
|
1894
|
+
contentType: "image/png",
|
|
1895
|
+
traceId,
|
|
1896
|
+
observationId: spanId,
|
|
1897
|
+
field: "output"
|
|
1898
|
+
});
|
|
1899
|
+
this.failures = 0;
|
|
1900
|
+
return reference.toString();
|
|
1901
|
+
} catch (error) {
|
|
1902
|
+
return this.failed(error);
|
|
1903
|
+
}
|
|
1904
|
+
}
|
|
1905
|
+
failed(error) {
|
|
1906
|
+
this.failures += 1;
|
|
1907
|
+
if (!this.warned) {
|
|
1908
|
+
this.warned = true;
|
|
1909
|
+
this.warn(
|
|
1910
|
+
`native computer: screenshot upload failed (${errorName(error)}: ${error instanceof Error ? error.message : String(error)}); spans keep going without it`
|
|
1911
|
+
);
|
|
1912
|
+
}
|
|
1913
|
+
return `[screenshot not uploaded: ${errorName(error)}]`;
|
|
1914
|
+
}
|
|
1915
|
+
};
|
|
1916
|
+
}
|
|
1917
|
+
});
|
|
1918
|
+
|
|
1919
|
+
// src/worlds/nativeComputer/base.ts
|
|
1920
|
+
function readField(item, ...names) {
|
|
1921
|
+
const record = item ?? {};
|
|
1922
|
+
return names.map((name) => record[name]).find((value) => value !== void 0 && value !== null);
|
|
1923
|
+
}
|
|
1924
|
+
var REPLAYABLE, SETTLING, EVENT_PREFIX, NativeComputer;
|
|
1925
|
+
var init_base = __esm({
|
|
1926
|
+
"src/worlds/nativeComputer/base.ts"() {
|
|
1927
|
+
"use strict";
|
|
1928
|
+
init_browser();
|
|
1929
|
+
init_actions();
|
|
1930
|
+
init_display();
|
|
1931
|
+
init_screen();
|
|
1932
|
+
init_trace();
|
|
1933
|
+
REPLAYABLE = /* @__PURE__ */ new Set(["screenshot", "zoom", "cursor_position", "wait"]);
|
|
1934
|
+
SETTLING = /* @__PURE__ */ new Set(["click", "mouse_up", "drag", "key", "history"]);
|
|
1935
|
+
EVENT_PREFIX = "computer_";
|
|
1936
|
+
NativeComputer = class _NativeComputer {
|
|
1937
|
+
constructor(browser, options = {}) {
|
|
1938
|
+
this.browser = browser;
|
|
1939
|
+
const kind = this.constructor;
|
|
1940
|
+
this.display = Display.forViewport(
|
|
1941
|
+
browser.viewport,
|
|
1942
|
+
options.display,
|
|
1943
|
+
(w, h) => kind.fits(w, h)
|
|
1944
|
+
);
|
|
1945
|
+
this.screen = new Screen(browser, this.display);
|
|
1946
|
+
this.tracer = options.tracer ?? ActionTracer.fromEnv();
|
|
1947
|
+
}
|
|
1948
|
+
browser;
|
|
1949
|
+
static kinds = /* @__PURE__ */ new Map();
|
|
1950
|
+
display;
|
|
1951
|
+
screen;
|
|
1952
|
+
tracer;
|
|
1953
|
+
queue = Promise.resolve();
|
|
1954
|
+
static register(provider, kind) {
|
|
1955
|
+
_NativeComputer.kinds.set(provider, kind);
|
|
1956
|
+
}
|
|
1957
|
+
static get providers() {
|
|
1958
|
+
return [..._NativeComputer.kinds.keys()].sort();
|
|
1959
|
+
}
|
|
1960
|
+
static forProvider(provider, browser, options = {}) {
|
|
1961
|
+
const Kind = _NativeComputer.kinds.get(provider);
|
|
1962
|
+
if (!Kind)
|
|
1963
|
+
throw new Error(
|
|
1964
|
+
`unknown computer-use provider '${provider}'; choose from ${_NativeComputer.providers.join(", ")}`
|
|
1965
|
+
);
|
|
1966
|
+
return new Kind(browser, options);
|
|
1967
|
+
}
|
|
1968
|
+
/** Whether a screenshot of this size is within the provider's limits. */
|
|
1969
|
+
static fits(_width, _height) {
|
|
1970
|
+
return true;
|
|
1971
|
+
}
|
|
1972
|
+
/** Run one provider-shaped action (an OpenAI action object, or an Anthropic
|
|
1973
|
+
* `{ action: "left_click", ... }` input) and return what it produced: the
|
|
1974
|
+
* door for any agent framework that hands actions over one at a time. */
|
|
1975
|
+
executeAction(raw) {
|
|
1976
|
+
return this.perform(this.parse(raw));
|
|
1977
|
+
}
|
|
1978
|
+
/** Run one action on the page: reported on the session's browser timeline
|
|
1979
|
+
* and, when tracing is on, as a span with the screen after. */
|
|
1980
|
+
async perform(action) {
|
|
1981
|
+
const secret = action.name === "type" && await this.screen.focusedFieldIsSecret();
|
|
1982
|
+
const event = EVENT_PREFIX + action.name;
|
|
1983
|
+
const args = redactActionArgs(event, action.recordArgs(secret));
|
|
1984
|
+
return this.tracer.span(
|
|
1985
|
+
action,
|
|
1986
|
+
args,
|
|
1987
|
+
() => this.browser.act(
|
|
1988
|
+
event,
|
|
1989
|
+
args,
|
|
1990
|
+
() => this.runOnScreen(action),
|
|
1991
|
+
this.onLoss(action)
|
|
1992
|
+
),
|
|
1993
|
+
() => this.screen.screenshot(),
|
|
1994
|
+
(text2) => this.browser.scrub(text2)
|
|
1995
|
+
);
|
|
1996
|
+
}
|
|
1997
|
+
async performAll(actions) {
|
|
1998
|
+
const results = [];
|
|
1999
|
+
for (const action of actions) results.push(await this.perform(action));
|
|
2000
|
+
return results;
|
|
2001
|
+
}
|
|
2002
|
+
/** The screen as the model sees it, as a traced `screenshot` action. */
|
|
2003
|
+
async screenshot() {
|
|
2004
|
+
return (await this.perform(new ComputerAction("screenshot"))).image ?? Buffer.alloc(0);
|
|
2005
|
+
}
|
|
2006
|
+
/** Run `fn` after every earlier call made through here: the AI SDK starts a
|
|
2007
|
+
* step's tool calls concurrently, but one screen takes one action at a time. */
|
|
2008
|
+
serial(fn) {
|
|
2009
|
+
const next = this.queue.then(fn, fn);
|
|
2010
|
+
this.queue = next.catch(() => void 0);
|
|
2011
|
+
return next;
|
|
2012
|
+
}
|
|
2013
|
+
async runOnScreen(action) {
|
|
2014
|
+
const result = await this.screen.run(action);
|
|
2015
|
+
if (SETTLING.has(action.name)) await this.browser.settle();
|
|
2016
|
+
return result;
|
|
2017
|
+
}
|
|
2018
|
+
onLoss(action) {
|
|
2019
|
+
return REPLAYABLE.has(action.name) ? "retry" : "report";
|
|
2020
|
+
}
|
|
2021
|
+
};
|
|
2022
|
+
}
|
|
2023
|
+
});
|
|
2024
|
+
|
|
2025
|
+
// src/worlds/nativeComputer/keys.ts
|
|
2026
|
+
function playwrightKey(token) {
|
|
2027
|
+
return KEY_NAMES[token.toLowerCase()] ?? token;
|
|
2028
|
+
}
|
|
2029
|
+
function letterOrName(key2) {
|
|
2030
|
+
return /^[a-zA-Z]$/.test(key2) ? key2.toLowerCase() : playwrightKey(key2);
|
|
2031
|
+
}
|
|
2032
|
+
function modifierChord(text2) {
|
|
2033
|
+
return typeof text2 === "string" && text2 ? [...KeyChord.fromXdotool(text2).keys] : [];
|
|
2034
|
+
}
|
|
2035
|
+
function modifierKeys(keys) {
|
|
2036
|
+
return Array.isArray(keys) && keys.length > 0 ? [...KeyChord.fromKeys(keys.map(String)).keys] : [];
|
|
2037
|
+
}
|
|
2038
|
+
var F_KEYS, KEY_NAMES, KeyChord;
|
|
2039
|
+
var init_keys = __esm({
|
|
2040
|
+
"src/worlds/nativeComputer/keys.ts"() {
|
|
2041
|
+
"use strict";
|
|
2042
|
+
F_KEYS = Object.fromEntries(
|
|
2043
|
+
Array.from({ length: 12 }, (_, i) => [`f${i + 1}`, `F${i + 1}`])
|
|
2044
|
+
);
|
|
2045
|
+
KEY_NAMES = {
|
|
2046
|
+
return: "Enter",
|
|
2047
|
+
enter: "Enter",
|
|
2048
|
+
kp_enter: "Enter",
|
|
2049
|
+
esc: "Escape",
|
|
2050
|
+
escape: "Escape",
|
|
2051
|
+
tab: "Tab",
|
|
2052
|
+
space: "Space",
|
|
2053
|
+
backspace: "Backspace",
|
|
2054
|
+
delete: "Delete",
|
|
2055
|
+
del: "Delete",
|
|
2056
|
+
insert: "Insert",
|
|
2057
|
+
home: "Home",
|
|
2058
|
+
end: "End",
|
|
2059
|
+
pageup: "PageUp",
|
|
2060
|
+
page_up: "PageUp",
|
|
2061
|
+
prior: "PageUp",
|
|
2062
|
+
pagedown: "PageDown",
|
|
2063
|
+
page_down: "PageDown",
|
|
2064
|
+
next: "PageDown",
|
|
2065
|
+
up: "ArrowUp",
|
|
2066
|
+
arrowup: "ArrowUp",
|
|
2067
|
+
down: "ArrowDown",
|
|
2068
|
+
arrowdown: "ArrowDown",
|
|
2069
|
+
left: "ArrowLeft",
|
|
2070
|
+
arrowleft: "ArrowLeft",
|
|
2071
|
+
right: "ArrowRight",
|
|
2072
|
+
arrowright: "ArrowRight",
|
|
2073
|
+
ctrl: "Control",
|
|
2074
|
+
control: "Control",
|
|
2075
|
+
shift: "Shift",
|
|
2076
|
+
alt: "Alt",
|
|
2077
|
+
option: "Alt",
|
|
2078
|
+
super: "Meta",
|
|
2079
|
+
meta: "Meta",
|
|
2080
|
+
cmd: "Meta",
|
|
2081
|
+
command: "Meta",
|
|
2082
|
+
win: "Meta",
|
|
2083
|
+
capslock: "CapsLock",
|
|
2084
|
+
caps_lock: "CapsLock",
|
|
2085
|
+
plus: "+",
|
|
2086
|
+
minus: "-",
|
|
2087
|
+
...F_KEYS
|
|
2088
|
+
};
|
|
2089
|
+
KeyChord = class _KeyChord {
|
|
2090
|
+
constructor(keys) {
|
|
2091
|
+
this.keys = keys;
|
|
2092
|
+
if (keys.length === 0)
|
|
2093
|
+
throw new Error("a key action needs at least one key");
|
|
2094
|
+
}
|
|
2095
|
+
keys;
|
|
2096
|
+
/** `ctrl+shift+t` / `Return`: Anthropic's vocabulary, case kept. */
|
|
2097
|
+
static fromXdotool(text2) {
|
|
2098
|
+
return new _KeyChord(
|
|
2099
|
+
text2.trim().split("+").filter(Boolean).map(playwrightKey)
|
|
2100
|
+
);
|
|
2101
|
+
}
|
|
2102
|
+
/** `["CTRL", "A"]`: OpenAI's vocabulary. A lone letter is the unshifted key. */
|
|
2103
|
+
static fromKeys(keys) {
|
|
2104
|
+
return new _KeyChord(keys.map(letterOrName));
|
|
2105
|
+
}
|
|
2106
|
+
/** What `page.keyboard.press` takes: `Control+a`. */
|
|
2107
|
+
get combo() {
|
|
2108
|
+
return this.keys.join("+");
|
|
2109
|
+
}
|
|
2110
|
+
};
|
|
2111
|
+
}
|
|
2112
|
+
});
|
|
2113
|
+
|
|
2114
|
+
// src/worlds/nativeComputer/anthropic.ts
|
|
2115
|
+
function required(raw, key2) {
|
|
2116
|
+
const value = raw[key2];
|
|
2117
|
+
if (value === void 0 || value === null)
|
|
2118
|
+
throw new Error(`${String(raw.action)} needs ${key2}`);
|
|
2119
|
+
return value;
|
|
2120
|
+
}
|
|
2121
|
+
function pair(raw, key2) {
|
|
2122
|
+
const value = required(raw, key2);
|
|
2123
|
+
return [toInt(value[0]), toInt(value[1])];
|
|
2124
|
+
}
|
|
2125
|
+
function point(raw) {
|
|
2126
|
+
if (raw.coordinate === void 0 || raw.coordinate === null) return {};
|
|
2127
|
+
const [x, y] = pair(raw, "coordinate");
|
|
2128
|
+
return { x, y };
|
|
2129
|
+
}
|
|
2130
|
+
function chord(raw) {
|
|
2131
|
+
return [...KeyChord.fromXdotool(String(required(raw, "text"))).keys];
|
|
2132
|
+
}
|
|
2133
|
+
function click(button, count) {
|
|
2134
|
+
return (raw) => new ComputerAction("click", {
|
|
2135
|
+
...point(raw),
|
|
2136
|
+
button,
|
|
2137
|
+
count,
|
|
2138
|
+
modifiers: modifierChord(raw.text)
|
|
2139
|
+
});
|
|
2140
|
+
}
|
|
2141
|
+
var SCROLL_STEP_PX, NOT_EXECUTED, MAX_ERROR2, SCROLL_DIRECTIONS, MEMBERS, AnthropicComputer, AnthropicComputer20251124;
|
|
2142
|
+
var init_anthropic = __esm({
|
|
2143
|
+
"src/worlds/nativeComputer/anthropic.ts"() {
|
|
2144
|
+
"use strict";
|
|
2145
|
+
init_actions();
|
|
2146
|
+
init_base();
|
|
2147
|
+
init_keys();
|
|
2148
|
+
SCROLL_STEP_PX = 100;
|
|
2149
|
+
NOT_EXECUTED = "Not executed: an earlier computer action in this turn failed.";
|
|
2150
|
+
MAX_ERROR2 = 1e3;
|
|
2151
|
+
SCROLL_DIRECTIONS = {
|
|
2152
|
+
up: [0, -1],
|
|
2153
|
+
down: [0, 1],
|
|
2154
|
+
left: [-1, 0],
|
|
2155
|
+
right: [1, 0]
|
|
2156
|
+
};
|
|
2157
|
+
MEMBERS = {
|
|
2158
|
+
screenshot: () => new ComputerAction("screenshot"),
|
|
2159
|
+
zoom: (raw) => new ComputerAction("zoom", {
|
|
2160
|
+
region: required(raw, "region").map(toInt)
|
|
2161
|
+
}),
|
|
2162
|
+
left_click: click("left", 1),
|
|
2163
|
+
right_click: click("right", 1),
|
|
2164
|
+
middle_click: click("middle", 1),
|
|
2165
|
+
double_click: click("left", 2),
|
|
2166
|
+
triple_click: click("left", 3),
|
|
2167
|
+
left_click_drag: (raw) => new ComputerAction("drag", {
|
|
2168
|
+
path: [pair(raw, "start_coordinate"), pair(raw, "coordinate")],
|
|
2169
|
+
modifiers: modifierChord(raw.text)
|
|
2170
|
+
}),
|
|
2171
|
+
mouse_move: (raw) => {
|
|
2172
|
+
const [x, y] = pair(raw, "coordinate");
|
|
2173
|
+
return new ComputerAction("move", { x, y });
|
|
2174
|
+
},
|
|
2175
|
+
left_mouse_down: () => new ComputerAction("mouse_down", { button: "left" }),
|
|
2176
|
+
left_mouse_up: () => new ComputerAction("mouse_up", { button: "left" }),
|
|
2177
|
+
cursor_position: () => new ComputerAction("cursor_position"),
|
|
2178
|
+
scroll: (raw) => {
|
|
2179
|
+
const direction = String(raw.scroll_direction ?? "down");
|
|
2180
|
+
if (!Object.hasOwn(SCROLL_DIRECTIONS, direction))
|
|
2181
|
+
throw new Error(
|
|
2182
|
+
`scroll_direction must be one of ${Object.keys(SCROLL_DIRECTIONS).join(", ")}`
|
|
2183
|
+
);
|
|
2184
|
+
const [dx, dy] = SCROLL_DIRECTIONS[direction];
|
|
2185
|
+
const amount = toInt(raw.scroll_amount ?? 1) * SCROLL_STEP_PX;
|
|
2186
|
+
return new ComputerAction("scroll", {
|
|
2187
|
+
...point(raw),
|
|
2188
|
+
dx: dx * amount,
|
|
2189
|
+
dy: dy * amount,
|
|
2190
|
+
modifiers: modifierChord(raw.text)
|
|
2191
|
+
});
|
|
2192
|
+
},
|
|
2193
|
+
type: (raw) => new ComputerAction("type", { text: String(required(raw, "text")) }),
|
|
2194
|
+
key: (raw) => new ComputerAction("key", {
|
|
2195
|
+
keys: chord(raw),
|
|
2196
|
+
repeat: toInt(raw.repeat ?? 1)
|
|
2197
|
+
}),
|
|
2198
|
+
hold_key: (raw) => new ComputerAction("hold_key", {
|
|
2199
|
+
keys: chord(raw),
|
|
2200
|
+
seconds: toNumber(required(raw, "duration"))
|
|
2201
|
+
}),
|
|
2202
|
+
wait: (raw) => new ComputerAction("wait", { seconds: toNumber(raw.duration ?? 1) })
|
|
2203
|
+
};
|
|
2204
|
+
AnthropicComputer = class _AnthropicComputer extends NativeComputer {
|
|
2205
|
+
static TOOL_TYPE = "computer_toolset_20260801";
|
|
2206
|
+
static TOOLSET = "computer";
|
|
2207
|
+
static BETA = null;
|
|
2208
|
+
static MAX_LONG_EDGE = 2576;
|
|
2209
|
+
static MAX_VISUAL_TOKENS = 4784;
|
|
2210
|
+
static PATCH_PX = 28;
|
|
2211
|
+
static fits(width, height) {
|
|
2212
|
+
const tokens = Math.ceil(width / this.PATCH_PX) * Math.ceil(height / this.PATCH_PX);
|
|
2213
|
+
return Math.max(width, height) <= this.MAX_LONG_EDGE && tokens <= this.MAX_VISUAL_TOKENS;
|
|
2214
|
+
}
|
|
2215
|
+
tool() {
|
|
2216
|
+
return { type: _AnthropicComputer.TOOL_TYPE };
|
|
2217
|
+
}
|
|
2218
|
+
/** Whether a content block is a call to this computer. */
|
|
2219
|
+
owns(block) {
|
|
2220
|
+
return readField(block, "type") === "tool_use" && readField(block, "toolset_name") === _AnthropicComputer.TOOLSET;
|
|
2221
|
+
}
|
|
2222
|
+
member(block) {
|
|
2223
|
+
return [
|
|
2224
|
+
String(readField(block, "name")),
|
|
2225
|
+
{ ...readField(block, "input") ?? {} }
|
|
2226
|
+
];
|
|
2227
|
+
}
|
|
2228
|
+
parse(raw) {
|
|
2229
|
+
const name = String(readField(raw, "action"));
|
|
2230
|
+
const parser = Object.hasOwn(MEMBERS, name) ? MEMBERS[name] : void 0;
|
|
2231
|
+
if (!parser) throw new Error(`unknown computer action: ${name}`);
|
|
2232
|
+
return parser(raw);
|
|
2233
|
+
}
|
|
2234
|
+
/** Run every computer `tool_use` in a response's content, in order, and
|
|
2235
|
+
* return one `tool_result` per block. Other blocks are skipped. */
|
|
2236
|
+
async execute(content) {
|
|
2237
|
+
const results = [];
|
|
2238
|
+
let failed = false;
|
|
2239
|
+
for (const block of content) {
|
|
2240
|
+
if (!this.owns(block)) continue;
|
|
2241
|
+
if (failed) {
|
|
2242
|
+
results.push(this.envelope(block, NOT_EXECUTED, true));
|
|
2243
|
+
continue;
|
|
2244
|
+
}
|
|
2245
|
+
const [result, blockFailed] = await this.runBlock(block);
|
|
2246
|
+
results.push(result);
|
|
2247
|
+
failed = blockFailed;
|
|
2248
|
+
}
|
|
2249
|
+
return results;
|
|
2250
|
+
}
|
|
2251
|
+
/** The content an `ActionResult` goes back to the model as. */
|
|
2252
|
+
static content(result) {
|
|
2253
|
+
if (result.image)
|
|
2254
|
+
return [
|
|
2255
|
+
{
|
|
2256
|
+
type: "image",
|
|
2257
|
+
source: {
|
|
2258
|
+
type: "base64",
|
|
2259
|
+
media_type: "image/png",
|
|
2260
|
+
data: result.image.toString("base64")
|
|
2261
|
+
}
|
|
2262
|
+
}
|
|
2263
|
+
];
|
|
2264
|
+
return [{ type: "text", text: result.text ?? "OK" }];
|
|
2265
|
+
}
|
|
2266
|
+
/** For `anthropic.tools.computerToolset_20260801({ ...computer.aiSdk() })`
|
|
2267
|
+
* (or `computer_20251124` with the legacy kind): `execute` runs one action
|
|
2268
|
+
* and returns `{ type: "image", data }` or text; `toModelOutput` turns that
|
|
2269
|
+
* into the tool result. Calls run one at a time, and once a call fails the
|
|
2270
|
+
* rest of that step's calls answer as not executed. */
|
|
2271
|
+
aiSdk() {
|
|
2272
|
+
let failedStep;
|
|
2273
|
+
const execute = (input, options) => this.serial(async () => {
|
|
2274
|
+
const step = options?.messages?.length;
|
|
2275
|
+
if (step !== void 0 && step === failedStep)
|
|
2276
|
+
throw new Error(NOT_EXECUTED);
|
|
2277
|
+
try {
|
|
2278
|
+
return _AnthropicComputer.aiSdkOutput(await this.executeAction(input));
|
|
2279
|
+
} catch (error) {
|
|
2280
|
+
failedStep = step;
|
|
2281
|
+
throw error instanceof Error ? new Error(this.browser.scrub(error.message)) : error;
|
|
2282
|
+
}
|
|
2283
|
+
});
|
|
2284
|
+
return {
|
|
2285
|
+
execute,
|
|
2286
|
+
toModelOutput: ({ output }) => _AnthropicComputer.aiSdkModelOutput(output)
|
|
2287
|
+
};
|
|
2288
|
+
}
|
|
2289
|
+
static aiSdkOutput(result) {
|
|
2290
|
+
if (result.image)
|
|
2291
|
+
return { type: "image", data: result.image.toString("base64") };
|
|
2292
|
+
return result.text ?? "OK";
|
|
2293
|
+
}
|
|
2294
|
+
/** `image-data` is what AI SDK 6's Anthropic provider turns into an image
|
|
2295
|
+
* block; AI SDK 7 still accepts it (and converts it to a `file` part). */
|
|
2296
|
+
static aiSdkModelOutput(output) {
|
|
2297
|
+
if (typeof output === "string") return { type: "text", value: output };
|
|
2298
|
+
return {
|
|
2299
|
+
type: "content",
|
|
2300
|
+
value: [
|
|
2301
|
+
{ type: "image-data", data: output.data, mediaType: "image/png" }
|
|
2302
|
+
]
|
|
2303
|
+
};
|
|
2304
|
+
}
|
|
2305
|
+
envelope(block, content, isError = false) {
|
|
2306
|
+
return {
|
|
2307
|
+
type: "tool_result",
|
|
2308
|
+
tool_use_id: String(readField(block, "id")),
|
|
2309
|
+
toolset_name: _AnthropicComputer.TOOLSET,
|
|
2310
|
+
content,
|
|
2311
|
+
...isError ? { is_error: true } : {}
|
|
2312
|
+
};
|
|
2313
|
+
}
|
|
2314
|
+
async runBlock(block) {
|
|
2315
|
+
const [name, payload] = this.member(block);
|
|
2316
|
+
try {
|
|
2317
|
+
const result = await this.executeAction({ ...payload, action: name });
|
|
2318
|
+
return [this.envelope(block, _AnthropicComputer.content(result)), false];
|
|
2319
|
+
} catch (error) {
|
|
2320
|
+
const detail = error instanceof Error ? `${error.name}: ${error.message}` : String(error);
|
|
2321
|
+
return [
|
|
2322
|
+
this.envelope(
|
|
2323
|
+
block,
|
|
2324
|
+
this.browser.scrub(`Error: ${detail}`).slice(0, MAX_ERROR2),
|
|
2325
|
+
true
|
|
2326
|
+
),
|
|
2327
|
+
true
|
|
2328
|
+
];
|
|
2329
|
+
}
|
|
2330
|
+
}
|
|
2331
|
+
};
|
|
2332
|
+
AnthropicComputer20251124 = class _AnthropicComputer20251124 extends AnthropicComputer {
|
|
2333
|
+
static TOOL_TYPE = "computer_20251124";
|
|
2334
|
+
static BETA = "computer-use-2025-11-24";
|
|
2335
|
+
static MAX_LONG_EDGE = 1568;
|
|
2336
|
+
static MAX_PIXELS = 115e4;
|
|
2337
|
+
static fits(width, height) {
|
|
2338
|
+
return Math.max(width, height) <= this.MAX_LONG_EDGE && width * height <= this.MAX_PIXELS;
|
|
2339
|
+
}
|
|
2340
|
+
tool() {
|
|
2341
|
+
return {
|
|
2342
|
+
type: _AnthropicComputer20251124.TOOL_TYPE,
|
|
2343
|
+
name: AnthropicComputer.TOOLSET,
|
|
2344
|
+
display_width_px: this.display.width,
|
|
2345
|
+
display_height_px: this.display.height,
|
|
2346
|
+
enable_zoom: true
|
|
2347
|
+
};
|
|
2348
|
+
}
|
|
2349
|
+
owns(block) {
|
|
2350
|
+
return readField(block, "type") === "tool_use" && readField(block, "name") === AnthropicComputer.TOOLSET;
|
|
2351
|
+
}
|
|
2352
|
+
member(block) {
|
|
2353
|
+
const { action, ...payload } = readField(block, "input") ?? {};
|
|
2354
|
+
return [String(action ?? ""), payload];
|
|
2355
|
+
}
|
|
2356
|
+
envelope(block, content, isError = false) {
|
|
2357
|
+
const { toolset_name: _dropped, ...rest } = super.envelope(
|
|
2358
|
+
block,
|
|
2359
|
+
content,
|
|
2360
|
+
isError
|
|
2361
|
+
);
|
|
2362
|
+
return rest;
|
|
2363
|
+
}
|
|
2364
|
+
};
|
|
2365
|
+
NativeComputer.register("anthropic", AnthropicComputer);
|
|
2366
|
+
NativeComputer.register(
|
|
2367
|
+
"anthropic-computer-20251124",
|
|
2368
|
+
AnthropicComputer20251124
|
|
2369
|
+
);
|
|
2370
|
+
}
|
|
2371
|
+
});
|
|
2372
|
+
|
|
2373
|
+
// src/worlds/nativeComputer/openai.ts
|
|
2374
|
+
function safetyCheck(raw) {
|
|
2375
|
+
const check = { id: String(readField(raw, "id") ?? "") };
|
|
2376
|
+
const code = readField(raw, "code");
|
|
2377
|
+
const message = readField(raw, "message");
|
|
2378
|
+
if (code !== void 0) check.code = String(code);
|
|
2379
|
+
if (message !== void 0) check.message = String(message);
|
|
2380
|
+
return check;
|
|
2381
|
+
}
|
|
2382
|
+
function dataUrl(png) {
|
|
2383
|
+
return `data:image/png;base64,${png.toString("base64")}`;
|
|
2384
|
+
}
|
|
2385
|
+
function xy(raw) {
|
|
2386
|
+
return {
|
|
2387
|
+
x: toInt(readField(raw, "x") ?? 0),
|
|
2388
|
+
y: toInt(readField(raw, "y") ?? 0)
|
|
2389
|
+
};
|
|
2390
|
+
}
|
|
2391
|
+
function held(raw) {
|
|
2392
|
+
return modifierKeys(readField(raw, "keys"));
|
|
2393
|
+
}
|
|
2394
|
+
var WAIT_SECONDS, BUTTONS, HISTORY_BUTTONS, PendingSafetyChecks, ACTIONS, OpenAIComputer, OpenAIPreviewComputer;
|
|
2395
|
+
var init_openai = __esm({
|
|
2396
|
+
"src/worlds/nativeComputer/openai.ts"() {
|
|
2397
|
+
"use strict";
|
|
2398
|
+
init_actions();
|
|
2399
|
+
init_base();
|
|
2400
|
+
init_keys();
|
|
2401
|
+
WAIT_SECONDS = 1;
|
|
2402
|
+
BUTTONS = {
|
|
2403
|
+
left: "left",
|
|
2404
|
+
right: "right",
|
|
2405
|
+
wheel: "middle",
|
|
2406
|
+
middle: "middle"
|
|
2407
|
+
};
|
|
2408
|
+
HISTORY_BUTTONS = /* @__PURE__ */ new Set(["back", "forward"]);
|
|
2409
|
+
PendingSafetyChecks = class extends Error {
|
|
2410
|
+
constructor(callId, checks) {
|
|
2411
|
+
const listed = checks.map((c) => `${c.code ?? "check"}: ${c.message ?? ""}`.trim()).join("; ");
|
|
2412
|
+
super(
|
|
2413
|
+
`computer_call ${callId} needs ${checks.length} safety check(s) acknowledged: ${listed}`
|
|
2414
|
+
);
|
|
2415
|
+
this.callId = callId;
|
|
2416
|
+
this.checks = checks;
|
|
2417
|
+
this.name = "PendingSafetyChecks";
|
|
2418
|
+
}
|
|
2419
|
+
callId;
|
|
2420
|
+
checks;
|
|
2421
|
+
};
|
|
2422
|
+
ACTIONS = {
|
|
2423
|
+
click: (raw) => {
|
|
2424
|
+
const button = String(readField(raw, "button") ?? "left");
|
|
2425
|
+
if (HISTORY_BUTTONS.has(button))
|
|
2426
|
+
return new ComputerAction("history", {
|
|
2427
|
+
direction: button
|
|
2428
|
+
});
|
|
2429
|
+
if (!Object.hasOwn(BUTTONS, button))
|
|
2430
|
+
throw new Error(`unknown mouse button: ${button}`);
|
|
2431
|
+
return new ComputerAction("click", {
|
|
2432
|
+
...xy(raw),
|
|
2433
|
+
button: BUTTONS[button],
|
|
2434
|
+
count: 1,
|
|
2435
|
+
modifiers: held(raw)
|
|
2436
|
+
});
|
|
2437
|
+
},
|
|
2438
|
+
double_click: (raw) => new ComputerAction("click", {
|
|
2439
|
+
...xy(raw),
|
|
2440
|
+
button: "left",
|
|
2441
|
+
count: 2,
|
|
2442
|
+
modifiers: held(raw)
|
|
2443
|
+
}),
|
|
2444
|
+
drag: (raw) => new ComputerAction("drag", {
|
|
2445
|
+
path: (readField(raw, "path") ?? []).map(
|
|
2446
|
+
(p) => [toInt(readField(p, "x")), toInt(readField(p, "y"))]
|
|
2447
|
+
),
|
|
2448
|
+
modifiers: held(raw)
|
|
2449
|
+
}),
|
|
2450
|
+
keypress: (raw) => new ComputerAction("key", {
|
|
2451
|
+
keys: [
|
|
2452
|
+
...KeyChord.fromKeys(readField(raw, "keys") ?? []).keys
|
|
2453
|
+
],
|
|
2454
|
+
repeat: 1
|
|
2455
|
+
}),
|
|
2456
|
+
move: (raw) => new ComputerAction("move", { ...xy(raw), modifiers: held(raw) }),
|
|
2457
|
+
scroll: (raw) => new ComputerAction("scroll", {
|
|
2458
|
+
...xy(raw),
|
|
2459
|
+
dx: toInt(readField(raw, "scroll_x", "scrollX") ?? 0),
|
|
2460
|
+
dy: toInt(readField(raw, "scroll_y", "scrollY") ?? 0),
|
|
2461
|
+
modifiers: held(raw)
|
|
2462
|
+
}),
|
|
2463
|
+
type: (raw) => new ComputerAction("type", { text: String(readField(raw, "text") ?? "") }),
|
|
2464
|
+
wait: () => new ComputerAction("wait", { seconds: WAIT_SECONDS }),
|
|
2465
|
+
screenshot: () => new ComputerAction("screenshot")
|
|
2466
|
+
};
|
|
2467
|
+
OpenAIComputer = class _OpenAIComputer extends NativeComputer {
|
|
2468
|
+
tool() {
|
|
2469
|
+
return { type: "computer" };
|
|
2470
|
+
}
|
|
2471
|
+
owns(item) {
|
|
2472
|
+
return readField(item, "type") === "computer_call";
|
|
2473
|
+
}
|
|
2474
|
+
parse(raw) {
|
|
2475
|
+
const kind = String(readField(raw, "type"));
|
|
2476
|
+
const parser = Object.hasOwn(ACTIONS, kind) ? ACTIONS[kind] : void 0;
|
|
2477
|
+
if (!parser) throw new Error(`unknown computer action: ${kind}`);
|
|
2478
|
+
return parser(raw);
|
|
2479
|
+
}
|
|
2480
|
+
static actionsOf(call) {
|
|
2481
|
+
const batch = readField(call, "actions");
|
|
2482
|
+
if (Array.isArray(batch)) return batch;
|
|
2483
|
+
const single = readField(call, "action");
|
|
2484
|
+
return single === void 0 ? [] : [single];
|
|
2485
|
+
}
|
|
2486
|
+
/** Run a `computer_call`'s actions and return its `computer_call_output`.
|
|
2487
|
+
* Throws `PendingSafetyChecks` (before anything runs) while a check the
|
|
2488
|
+
* model raised is not in `acknowledged`. */
|
|
2489
|
+
async execute(call, acknowledged = []) {
|
|
2490
|
+
const callId = String(readField(call, "call_id", "callId"));
|
|
2491
|
+
const checks = (readField(
|
|
2492
|
+
call,
|
|
2493
|
+
"pending_safety_checks",
|
|
2494
|
+
"pendingSafetyChecks"
|
|
2495
|
+
) ?? []).map(safetyCheck);
|
|
2496
|
+
const png = await this.runCall(
|
|
2497
|
+
callId,
|
|
2498
|
+
_OpenAIComputer.actionsOf(call),
|
|
2499
|
+
checks,
|
|
2500
|
+
acknowledged
|
|
2501
|
+
);
|
|
2502
|
+
return {
|
|
2503
|
+
type: "computer_call_output",
|
|
2504
|
+
call_id: callId,
|
|
2505
|
+
output: {
|
|
2506
|
+
type: "computer_screenshot",
|
|
2507
|
+
image_url: dataUrl(png),
|
|
2508
|
+
detail: "original"
|
|
2509
|
+
},
|
|
2510
|
+
...checks.length > 0 ? { acknowledged_safety_checks: checks } : {}
|
|
2511
|
+
};
|
|
2512
|
+
}
|
|
2513
|
+
/** For `openai.tools.computer({ ...computer.aiSdk() })`: `execute` runs a
|
|
2514
|
+
* call's `actions` and returns the screenshot output. A call with pending
|
|
2515
|
+
* safety checks asks for approval first (`needsApproval`), so the AI SDK's
|
|
2516
|
+
* approval flow puts them in front of a person; once approved, `execute`
|
|
2517
|
+
* acknowledges them. */
|
|
2518
|
+
aiSdk() {
|
|
2519
|
+
return {
|
|
2520
|
+
needsApproval: (input) => (input.pendingSafetyChecks ?? []).length > 0,
|
|
2521
|
+
execute: (input) => this.serial(async () => {
|
|
2522
|
+
const checks = (input.pendingSafetyChecks ?? []).map(safetyCheck);
|
|
2523
|
+
const png = await this.runCall(
|
|
2524
|
+
"ai-sdk",
|
|
2525
|
+
input.actions ?? [],
|
|
2526
|
+
checks,
|
|
2527
|
+
checks
|
|
2528
|
+
);
|
|
2529
|
+
return {
|
|
2530
|
+
output: { type: "computer_screenshot", imageUrl: dataUrl(png) },
|
|
2531
|
+
...checks.length > 0 ? { acknowledgedSafetyChecks: checks } : {}
|
|
2532
|
+
};
|
|
2533
|
+
})
|
|
2534
|
+
};
|
|
2535
|
+
}
|
|
2536
|
+
/** The batch's actions, run after the safety checks clear; the screen after them. */
|
|
2537
|
+
async runCall(callId, rawActions, checks, acknowledged) {
|
|
2538
|
+
const cleared = new Set(acknowledged.map((c) => safetyCheck(c).id));
|
|
2539
|
+
const waiting = checks.filter((c) => !c.id || !cleared.has(c.id));
|
|
2540
|
+
if (waiting.length > 0) throw new PendingSafetyChecks(callId, waiting);
|
|
2541
|
+
const actions = rawActions.map((raw) => this.parse(raw));
|
|
2542
|
+
const results = await this.performAll(actions);
|
|
2543
|
+
const last = actions.at(-1);
|
|
2544
|
+
if (last?.name === "screenshot")
|
|
2545
|
+
return results.at(-1)?.image ?? Buffer.alloc(0);
|
|
2546
|
+
return this.screenshot();
|
|
2547
|
+
}
|
|
2548
|
+
};
|
|
2549
|
+
OpenAIPreviewComputer = class extends OpenAIComputer {
|
|
2550
|
+
tool() {
|
|
2551
|
+
return {
|
|
2552
|
+
type: "computer_use_preview",
|
|
2553
|
+
display_width: this.display.width,
|
|
2554
|
+
display_height: this.display.height,
|
|
2555
|
+
environment: "browser"
|
|
2556
|
+
};
|
|
2557
|
+
}
|
|
2558
|
+
};
|
|
2559
|
+
NativeComputer.register("openai", OpenAIComputer);
|
|
2560
|
+
NativeComputer.register("openai-preview", OpenAIPreviewComputer);
|
|
2561
|
+
}
|
|
2562
|
+
});
|
|
2563
|
+
|
|
2564
|
+
// src/worlds/nativeComputer/index.ts
|
|
2565
|
+
var init_nativeComputer = __esm({
|
|
2566
|
+
"src/worlds/nativeComputer/index.ts"() {
|
|
2567
|
+
"use strict";
|
|
2568
|
+
init_actions();
|
|
2569
|
+
init_base();
|
|
2570
|
+
init_display();
|
|
2571
|
+
init_keys();
|
|
2572
|
+
init_screen();
|
|
2573
|
+
init_trace();
|
|
2574
|
+
init_anthropic();
|
|
2575
|
+
init_openai();
|
|
2576
|
+
}
|
|
2577
|
+
});
|
|
2578
|
+
|
|
1312
2579
|
// src/worlds/sessionContract.ts
|
|
1313
2580
|
function serializeCallBody(body) {
|
|
1314
2581
|
const text2 = JSON.stringify(body);
|
|
@@ -1362,6 +2629,75 @@ var init_sessionContract = __esm({
|
|
|
1362
2629
|
}
|
|
1363
2630
|
});
|
|
1364
2631
|
|
|
2632
|
+
// src/tracing/session.ts
|
|
2633
|
+
var session_exports = {};
|
|
2634
|
+
__export(session_exports, {
|
|
2635
|
+
SESSION_ID_ATTRIBUTE: () => SESSION_ID_ATTRIBUTE,
|
|
2636
|
+
SessionSpanProcessor: () => SessionSpanProcessor,
|
|
2637
|
+
WORLD_SESSION_ID_ATTRIBUTE: () => WORLD_SESSION_ID_ATTRIBUTE,
|
|
2638
|
+
getAmbientSessionId: () => getAmbientSessionId,
|
|
2639
|
+
getCurrentWorldSessionId: () => getCurrentWorldSessionId,
|
|
2640
|
+
withSession: () => withSession,
|
|
2641
|
+
withWorldSession: () => withWorldSession
|
|
2642
|
+
});
|
|
2643
|
+
import { AsyncLocalStorage as AsyncLocalStorage2 } from "async_hooks";
|
|
2644
|
+
function getAmbientSessionId() {
|
|
2645
|
+
return currentSessionStorage.getStore();
|
|
2646
|
+
}
|
|
2647
|
+
function getCurrentWorldSessionId() {
|
|
2648
|
+
return currentWorldSessionStorage.getStore();
|
|
2649
|
+
}
|
|
2650
|
+
function runIn(storage, value, fn) {
|
|
2651
|
+
return new Promise((resolve11, reject) => {
|
|
2652
|
+
storage.run(value, () => {
|
|
2653
|
+
Promise.resolve().then(fn).then(resolve11, reject);
|
|
2654
|
+
});
|
|
2655
|
+
});
|
|
2656
|
+
}
|
|
2657
|
+
function withSession(sessionId, fn) {
|
|
2658
|
+
return runIn(currentSessionStorage, sessionId, fn);
|
|
2659
|
+
}
|
|
2660
|
+
function withWorldSession(worldSessionId, fn) {
|
|
2661
|
+
return runIn(
|
|
2662
|
+
currentWorldSessionStorage,
|
|
2663
|
+
worldSessionId,
|
|
2664
|
+
() => withSession(worldSessionId, fn)
|
|
2665
|
+
);
|
|
2666
|
+
}
|
|
2667
|
+
var SESSION_ID_ATTRIBUTE, WORLD_SESSION_ID_ATTRIBUTE, processStorage, currentSessionStorage, currentWorldSessionStorage, SessionSpanProcessor;
|
|
2668
|
+
var init_session = __esm({
|
|
2669
|
+
"src/tracing/session.ts"() {
|
|
2670
|
+
"use strict";
|
|
2671
|
+
SESSION_ID_ATTRIBUTE = "gateway.session.id";
|
|
2672
|
+
WORLD_SESSION_ID_ATTRIBUTE = "gateway.trace.metadata.world_session_id";
|
|
2673
|
+
processStorage = (name) => {
|
|
2674
|
+
const key2 = /* @__PURE__ */ Symbol.for(`@withgateway/sdk/${name}`);
|
|
2675
|
+
const slots = globalThis;
|
|
2676
|
+
slots[key2] ??= new AsyncLocalStorage2();
|
|
2677
|
+
return slots[key2];
|
|
2678
|
+
};
|
|
2679
|
+
currentSessionStorage = processStorage("session-storage");
|
|
2680
|
+
currentWorldSessionStorage = processStorage("world-session-storage");
|
|
2681
|
+
SessionSpanProcessor = class {
|
|
2682
|
+
onStart(span, _parentContext) {
|
|
2683
|
+
const worldSessionId = getCurrentWorldSessionId();
|
|
2684
|
+
if (worldSessionId)
|
|
2685
|
+
span.setAttribute(WORLD_SESSION_ID_ATTRIBUTE, worldSessionId);
|
|
2686
|
+
const sessionId = getAmbientSessionId();
|
|
2687
|
+
if (!sessionId || span.attributes?.[SESSION_ID_ATTRIBUTE] !== void 0)
|
|
2688
|
+
return;
|
|
2689
|
+
span.setAttribute(SESSION_ID_ATTRIBUTE, sessionId);
|
|
2690
|
+
}
|
|
2691
|
+
onEnd(_span) {
|
|
2692
|
+
}
|
|
2693
|
+
async shutdown() {
|
|
2694
|
+
}
|
|
2695
|
+
async forceFlush() {
|
|
2696
|
+
}
|
|
2697
|
+
};
|
|
2698
|
+
}
|
|
2699
|
+
});
|
|
2700
|
+
|
|
1365
2701
|
// src/worlds/taskRef.ts
|
|
1366
2702
|
var isTaskIdRef, isTaskSpec, taskLabel, assertTaskRef;
|
|
1367
2703
|
var init_taskRef = __esm({
|
|
@@ -1386,8 +2722,8 @@ var init_taskRef = __esm({
|
|
|
1386
2722
|
});
|
|
1387
2723
|
|
|
1388
2724
|
// src/worlds/session.ts
|
|
1389
|
-
var
|
|
1390
|
-
__export(
|
|
2725
|
+
var session_exports2 = {};
|
|
2726
|
+
__export(session_exports2, {
|
|
1391
2727
|
WorldSession: () => WorldSession,
|
|
1392
2728
|
WorldSessionCallError: () => WorldSessionCallError,
|
|
1393
2729
|
WorldSessionTimeout: () => WorldSessionTimeout,
|
|
@@ -1441,7 +2777,7 @@ function schemaFromSignature(spec) {
|
|
|
1441
2777
|
};
|
|
1442
2778
|
const inside = /\(([\s\S]*)\)\s*$/.exec(spec.signature.trim())?.[1] ?? "";
|
|
1443
2779
|
const properties = {};
|
|
1444
|
-
const
|
|
2780
|
+
const required2 = [];
|
|
1445
2781
|
const params = [];
|
|
1446
2782
|
let depth = 0;
|
|
1447
2783
|
let current = "";
|
|
@@ -1462,7 +2798,7 @@ function schemaFromSignature(spec) {
|
|
|
1462
2798
|
if (!name) continue;
|
|
1463
2799
|
if (eq === -1) {
|
|
1464
2800
|
properties[name] = { type: "string" };
|
|
1465
|
-
|
|
2801
|
+
required2.push(name);
|
|
1466
2802
|
continue;
|
|
1467
2803
|
}
|
|
1468
2804
|
const value = param.slice(eq + 1).trim();
|
|
@@ -1476,7 +2812,7 @@ function schemaFromSignature(spec) {
|
|
|
1476
2812
|
function: {
|
|
1477
2813
|
name: modelToolName(spec.name),
|
|
1478
2814
|
description: spec.doc ?? spec.name,
|
|
1479
|
-
parameters: { type: "object", properties, required }
|
|
2815
|
+
parameters: { type: "object", properties, required: required2 }
|
|
1480
2816
|
}
|
|
1481
2817
|
};
|
|
1482
2818
|
}
|
|
@@ -1545,13 +2881,16 @@ async function runSessions(opts) {
|
|
|
1545
2881
|
task = taskLabel(taskRef, session.taskInfo);
|
|
1546
2882
|
await session.ready();
|
|
1547
2883
|
const toolkit = await session.toolkit();
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
2884
|
+
const live = session;
|
|
2885
|
+
await live.withTraceContext(
|
|
2886
|
+
() => opts.agent({
|
|
2887
|
+
session: live,
|
|
2888
|
+
toolkit,
|
|
2889
|
+
instruction: live.instruction ?? (isTaskSpec(taskRef) ? taskRef.instruction : task),
|
|
2890
|
+
task,
|
|
2891
|
+
taskRef
|
|
2892
|
+
})
|
|
2893
|
+
);
|
|
1555
2894
|
const graded = await session.grade();
|
|
1556
2895
|
const result = {
|
|
1557
2896
|
task,
|
|
@@ -1589,12 +2928,14 @@ async function runSessions(opts) {
|
|
|
1589
2928
|
};
|
|
1590
2929
|
}
|
|
1591
2930
|
var READY_TIMEOUT_MS, READY_POLL_MS, CALL_TIMEOUT_MS, CALL_POLL_MS, JUDGED_GRADE_TIMEOUT_MS, JUDGED_GRADE_POLL_MS, EXPORT_PAGE, sleep2, modelToolName, WorldSessionTimeout, WorldSessionCallError, WorldSession, OPEN_SESSION_OPTION_KEYS, isOpenSessionOptions;
|
|
1592
|
-
var
|
|
2931
|
+
var init_session2 = __esm({
|
|
1593
2932
|
"src/worlds/session.ts"() {
|
|
1594
2933
|
"use strict";
|
|
1595
2934
|
init_worlds();
|
|
1596
2935
|
init_browser();
|
|
2936
|
+
init_nativeComputer();
|
|
1597
2937
|
init_sessionContract();
|
|
2938
|
+
init_session();
|
|
1598
2939
|
init_taskRef();
|
|
1599
2940
|
init_taskRef();
|
|
1600
2941
|
READY_TIMEOUT_MS = 10 * 6e4;
|
|
@@ -1748,6 +3089,12 @@ var init_session = __esm({
|
|
|
1748
3089
|
computerUseTools(browser) {
|
|
1749
3090
|
return computerUseToolkit(browser);
|
|
1750
3091
|
}
|
|
3092
|
+
/** The browser as a provider's own pixel-based computer-use tool: `anthropic`
|
|
3093
|
+
* (`computer_toolset_20260801`), `openai` (Responses `computer`),
|
|
3094
|
+
* `anthropic-computer-20251124` or `openai-preview`. See `nativeComputer/`. */
|
|
3095
|
+
nativeComputer(browser, provider = "anthropic", options = {}) {
|
|
3096
|
+
return NativeComputer.forProvider(provider, browser, options);
|
|
3097
|
+
}
|
|
1751
3098
|
/** The session's latest platform state (one request, no waiting). */
|
|
1752
3099
|
async status() {
|
|
1753
3100
|
const fresh = await apiRequest(
|
|
@@ -1982,6 +3329,21 @@ var init_session = __esm({
|
|
|
1982
3329
|
{ keepWarm: opts.keepWarm ?? false }
|
|
1983
3330
|
);
|
|
1984
3331
|
}
|
|
3332
|
+
/**
|
|
3333
|
+
* Run `fn` as work inside this session: spans it records take `sessionId`
|
|
3334
|
+
* as their session id and carry `world_session_id` trace metadata, so the
|
|
3335
|
+
* agent's traces land in the same session as the platform's traces of this
|
|
3336
|
+
* session's tool calls. A `withSession()` block inside still wins for the
|
|
3337
|
+
* session id. No effect before `tracing.init()`. `runSessions` wraps each
|
|
3338
|
+
* agent call in it.
|
|
3339
|
+
*
|
|
3340
|
+
* ```typescript
|
|
3341
|
+
* await session.withTraceContext(() => myAgent(toolkit, session.instruction));
|
|
3342
|
+
* ```
|
|
3343
|
+
*/
|
|
3344
|
+
withTraceContext(fn) {
|
|
3345
|
+
return withWorldSession(this.sessionId, fn);
|
|
3346
|
+
}
|
|
1985
3347
|
};
|
|
1986
3348
|
OPEN_SESSION_OPTION_KEYS = /* @__PURE__ */ new Set([
|
|
1987
3349
|
"task",
|
|
@@ -2131,7 +3493,11 @@ function fromResponse(answer, options) {
|
|
|
2131
3493
|
const worlds = {};
|
|
2132
3494
|
for (const [alias, state2] of Object.entries(answer.sessions)) {
|
|
2133
3495
|
sessions2[alias] = new WorldSession(state2.sessionId, state2, options);
|
|
2134
|
-
worlds[alias] = {
|
|
3496
|
+
worlds[alias] = {
|
|
3497
|
+
slug: state2.slug,
|
|
3498
|
+
ref: state2.ref,
|
|
3499
|
+
private: state2.private ?? null
|
|
3500
|
+
};
|
|
2135
3501
|
}
|
|
2136
3502
|
return new TaskSessions(
|
|
2137
3503
|
answer.taskId,
|
|
@@ -2205,6 +3571,7 @@ async function attachTask(taskId, options = {}) {
|
|
|
2205
3571
|
{
|
|
2206
3572
|
slug: row.slug ?? "",
|
|
2207
3573
|
ref: null,
|
|
3574
|
+
private: null,
|
|
2208
3575
|
versionId: row.versionId,
|
|
2209
3576
|
sessionId: row.sessionId,
|
|
2210
3577
|
ready: row.ready,
|
|
@@ -2234,7 +3601,7 @@ async function attachManifest(manifest, options = {}) {
|
|
|
2234
3601
|
Object.fromEntries(
|
|
2235
3602
|
Object.entries(manifest.sessions).map(([alias, entry]) => [
|
|
2236
3603
|
alias,
|
|
2237
|
-
{ slug: entry.slug, ref: entry.ref }
|
|
3604
|
+
{ slug: entry.slug, ref: entry.ref, private: entry.private ?? null }
|
|
2238
3605
|
])
|
|
2239
3606
|
)
|
|
2240
3607
|
);
|
|
@@ -2248,12 +3615,13 @@ var init_taskSessions = __esm({
|
|
|
2248
3615
|
"use strict";
|
|
2249
3616
|
init_worlds();
|
|
2250
3617
|
init_browser();
|
|
2251
|
-
|
|
3618
|
+
init_session2();
|
|
2252
3619
|
TASK_SESSIONS = "/api/public/world-task-sessions";
|
|
2253
3620
|
VERIFIER_REWARD_PREFIX = "x.";
|
|
2254
3621
|
manifestSession = (s, state2, world) => ({
|
|
2255
3622
|
slug: world.slug,
|
|
2256
3623
|
ref: world.ref,
|
|
3624
|
+
private: world.private,
|
|
2257
3625
|
versionId: state2.versionId,
|
|
2258
3626
|
sessionId: state2.sessionId,
|
|
2259
3627
|
ready: state2.ready,
|
|
@@ -2288,10 +3656,10 @@ var init_taskSessions = __esm({
|
|
|
2288
3656
|
sessions;
|
|
2289
3657
|
worlds;
|
|
2290
3658
|
hash;
|
|
2291
|
-
/** This alias's
|
|
2292
|
-
*
|
|
3659
|
+
/** This alias's world as recorded at open/attach — what a `TaskRun`
|
|
3660
|
+
* filing needs to name, without exposing the whole map. */
|
|
2293
3661
|
worldRef(alias) {
|
|
2294
|
-
return this.worlds[alias] ?? { slug: "", ref: null };
|
|
3662
|
+
return this.worlds[alias] ?? { slug: "", ref: null, private: null };
|
|
2295
3663
|
}
|
|
2296
3664
|
/** The aliases, in the spec's order. */
|
|
2297
3665
|
get aliases() {
|
|
@@ -2449,7 +3817,7 @@ var init_evals = __esm({
|
|
|
2449
3817
|
});
|
|
2450
3818
|
|
|
2451
3819
|
// src/tracing/identity.ts
|
|
2452
|
-
import { AsyncLocalStorage as
|
|
3820
|
+
import { AsyncLocalStorage as AsyncLocalStorage3 } from "async_hooks";
|
|
2453
3821
|
import { isSpanContextValid as isSpanContextValid2, trace as trace2 } from "@opentelemetry/api";
|
|
2454
3822
|
function resolveUserId() {
|
|
2455
3823
|
const contextual = currentUserStorage.getStore();
|
|
@@ -2502,7 +3870,7 @@ var init_identity = __esm({
|
|
|
2502
3870
|
"use strict";
|
|
2503
3871
|
init_users();
|
|
2504
3872
|
USER_ID_ATTRIBUTE = "gateway.user.id";
|
|
2505
|
-
currentUserStorage = new
|
|
3873
|
+
currentUserStorage = new AsyncLocalStorage3();
|
|
2506
3874
|
IdentitySpanProcessor = class {
|
|
2507
3875
|
onStart(span, _parentContext) {
|
|
2508
3876
|
const userId = resolveUserId();
|
|
@@ -2520,43 +3888,224 @@ var init_identity = __esm({
|
|
|
2520
3888
|
}
|
|
2521
3889
|
});
|
|
2522
3890
|
|
|
2523
|
-
// src/tracing/
|
|
2524
|
-
|
|
2525
|
-
|
|
2526
|
-
|
|
2527
|
-
|
|
2528
|
-
|
|
2529
|
-
|
|
2530
|
-
}
|
|
2531
|
-
|
|
2532
|
-
|
|
2533
|
-
return currentSessionStorage.getStore();
|
|
3891
|
+
// src/tracing/secrets.ts
|
|
3892
|
+
function jsonOrUndefined(text2) {
|
|
3893
|
+
let parsed;
|
|
3894
|
+
try {
|
|
3895
|
+
parsed = JSON.parse(text2);
|
|
3896
|
+
} catch {
|
|
3897
|
+
return void 0;
|
|
3898
|
+
}
|
|
3899
|
+
if (typeof parsed === "string") return parsed;
|
|
3900
|
+
return parsed !== null && typeof parsed === "object" ? parsed : void 0;
|
|
2534
3901
|
}
|
|
2535
|
-
function
|
|
2536
|
-
return
|
|
2537
|
-
|
|
2538
|
-
|
|
2539
|
-
|
|
3902
|
+
function encodings(value) {
|
|
3903
|
+
return [value, percentEncoded(value), JSON.stringify(value).slice(1, -1)];
|
|
3904
|
+
}
|
|
3905
|
+
function percentEncoded(value) {
|
|
3906
|
+
try {
|
|
3907
|
+
return encodeURIComponent(value);
|
|
3908
|
+
} catch {
|
|
3909
|
+
return value;
|
|
3910
|
+
}
|
|
3911
|
+
}
|
|
3912
|
+
function union(sets) {
|
|
3913
|
+
return new Set(sets.flatMap((set) => [...set]));
|
|
3914
|
+
}
|
|
3915
|
+
function leaves(value) {
|
|
3916
|
+
if (typeof value === "string") {
|
|
3917
|
+
return [...value].length >= MIN_SECRET_LENGTH ? /* @__PURE__ */ new Set([value]) : /* @__PURE__ */ new Set();
|
|
3918
|
+
}
|
|
3919
|
+
if (Array.isArray(value)) return union(value.map(leaves));
|
|
3920
|
+
if (value === null || typeof value !== "object") return /* @__PURE__ */ new Set();
|
|
3921
|
+
return union(Object.values(value).map(leaves));
|
|
3922
|
+
}
|
|
3923
|
+
function sameAttributes(before, after) {
|
|
3924
|
+
const keys = Object.keys(before);
|
|
3925
|
+
if (keys.length !== Object.keys(after).length) return false;
|
|
3926
|
+
return keys.every(
|
|
3927
|
+
(key2) => before[key2] === after[key2] || sameArray(before[key2], after[key2])
|
|
3928
|
+
);
|
|
3929
|
+
}
|
|
3930
|
+
function sameArray(before, after) {
|
|
3931
|
+
if (!Array.isArray(before) || !Array.isArray(after)) return false;
|
|
3932
|
+
return before.length === after.length && before.every((item, i) => item === after[i]);
|
|
3933
|
+
}
|
|
3934
|
+
function scrubbedRead(reads, property) {
|
|
3935
|
+
return typeof property === "string" && property in reads ? reads[property] : void 0;
|
|
3936
|
+
}
|
|
3937
|
+
function viewOf(span, reads) {
|
|
3938
|
+
const view = new Proxy(span, {
|
|
3939
|
+
get(target, property) {
|
|
3940
|
+
const read = scrubbedRead(reads, property);
|
|
3941
|
+
if (read) return read();
|
|
3942
|
+
const value = Reflect.get(target, property, target);
|
|
3943
|
+
if (typeof value !== "function") return value;
|
|
3944
|
+
return (...args) => {
|
|
3945
|
+
const result = value.apply(target, args);
|
|
3946
|
+
return result === target ? view : result;
|
|
3947
|
+
};
|
|
3948
|
+
},
|
|
3949
|
+
getOwnPropertyDescriptor(target, property) {
|
|
3950
|
+
const descriptor = Reflect.getOwnPropertyDescriptor(target, property);
|
|
3951
|
+
const read = scrubbedRead(reads, property);
|
|
3952
|
+
if (!read || !descriptor || !("value" in descriptor)) return descriptor;
|
|
3953
|
+
return { ...descriptor, value: read() };
|
|
3954
|
+
}
|
|
2540
3955
|
});
|
|
3956
|
+
return view;
|
|
2541
3957
|
}
|
|
2542
|
-
var
|
|
2543
|
-
var
|
|
2544
|
-
"src/tracing/
|
|
3958
|
+
var SECRET_KEYS, REDACTED2, MIN_SECRET_LENGTH, SpanSecrets, SPAN_SECRETS, SecretRedactingSpanProcessor;
|
|
3959
|
+
var init_secrets = __esm({
|
|
3960
|
+
"src/tracing/secrets.ts"() {
|
|
2545
3961
|
"use strict";
|
|
2546
|
-
|
|
2547
|
-
|
|
2548
|
-
|
|
2549
|
-
|
|
2550
|
-
|
|
2551
|
-
|
|
2552
|
-
|
|
3962
|
+
SECRET_KEYS = /* @__PURE__ */ new Set([
|
|
3963
|
+
"authorization_token",
|
|
3964
|
+
"authorizationToken"
|
|
3965
|
+
]);
|
|
3966
|
+
REDACTED2 = "[redacted: holds a credential]";
|
|
3967
|
+
MIN_SECRET_LENGTH = 8;
|
|
3968
|
+
SpanSecrets = class {
|
|
3969
|
+
constructor(keys = SECRET_KEYS) {
|
|
3970
|
+
this.keys = keys;
|
|
3971
|
+
}
|
|
3972
|
+
keys;
|
|
3973
|
+
isSecret(key2) {
|
|
3974
|
+
return this.keys.has(key2);
|
|
3975
|
+
}
|
|
3976
|
+
drops(attribute) {
|
|
3977
|
+
return this.mentions(attribute);
|
|
3978
|
+
}
|
|
3979
|
+
strip(value) {
|
|
3980
|
+
if (typeof value === "string") return this.stripNested(value);
|
|
3981
|
+
if (Array.isArray(value)) return value.map((item) => this.strip(item));
|
|
3982
|
+
if (value === null || typeof value !== "object") return value;
|
|
3983
|
+
return Object.fromEntries(
|
|
3984
|
+
Object.entries(value).filter(([key2]) => !this.isSecret(key2)).map(([key2, item]) => [key2, this.strip(item)])
|
|
3985
|
+
);
|
|
3986
|
+
}
|
|
3987
|
+
scrubAttribute(value) {
|
|
3988
|
+
try {
|
|
3989
|
+
return this.scrubbedValue(value);
|
|
3990
|
+
} catch {
|
|
3991
|
+
return Array.isArray(value) ? [REDACTED2] : REDACTED2;
|
|
2553
3992
|
}
|
|
2554
3993
|
}
|
|
2555
|
-
|
|
3994
|
+
scrubbedValue(value) {
|
|
3995
|
+
if (typeof value === "string") return this.scrubbedText(value);
|
|
3996
|
+
if (!Array.isArray(value)) return value;
|
|
3997
|
+
const results = value.map(
|
|
3998
|
+
(item) => typeof item === "string" ? this.cleaned(item) : { text: item, removed: /* @__PURE__ */ new Set() }
|
|
3999
|
+
);
|
|
4000
|
+
const removed = new Set(results.flatMap((r) => [...r.removed]));
|
|
4001
|
+
const scrubbed = results.map((r) => r.text);
|
|
4002
|
+
const withheld = scrubbed.some(
|
|
4003
|
+
(item) => typeof item === "string" && this.carries(item, removed)
|
|
4004
|
+
);
|
|
4005
|
+
return withheld ? [REDACTED2] : scrubbed;
|
|
2556
4006
|
}
|
|
2557
|
-
|
|
4007
|
+
scrubAttributes(attributes) {
|
|
4008
|
+
return Object.fromEntries(
|
|
4009
|
+
Object.entries(attributes).filter(([key2]) => !this.drops(key2)).map(([key2, value]) => [key2, this.scrubAttribute(value)])
|
|
4010
|
+
);
|
|
2558
4011
|
}
|
|
2559
|
-
|
|
4012
|
+
mentions(text2) {
|
|
4013
|
+
return [...this.keys].some((key2) => text2.includes(key2));
|
|
4014
|
+
}
|
|
4015
|
+
scrubbedText(text2) {
|
|
4016
|
+
const { text: cleaned, removed } = this.cleaned(text2);
|
|
4017
|
+
return this.carries(cleaned, removed) ? REDACTED2 : cleaned;
|
|
4018
|
+
}
|
|
4019
|
+
cleaned(text2) {
|
|
4020
|
+
if (!this.mentions(text2)) return { text: text2, removed: /* @__PURE__ */ new Set() };
|
|
4021
|
+
const parsed = jsonOrUndefined(text2);
|
|
4022
|
+
if (parsed === void 0) return { text: REDACTED2, removed: /* @__PURE__ */ new Set() };
|
|
4023
|
+
return {
|
|
4024
|
+
text: JSON.stringify(this.strip(parsed)),
|
|
4025
|
+
removed: this.removed(parsed)
|
|
4026
|
+
};
|
|
4027
|
+
}
|
|
4028
|
+
carries(text2, removed) {
|
|
4029
|
+
if (text2 === REDACTED2 || this.mentions(text2)) return true;
|
|
4030
|
+
return [...removed].some(
|
|
4031
|
+
(value) => encodings(value).some((form) => text2.includes(form))
|
|
4032
|
+
);
|
|
4033
|
+
}
|
|
4034
|
+
removed(value) {
|
|
4035
|
+
if (typeof value === "string") {
|
|
4036
|
+
const nested = this.mentions(value) ? jsonOrUndefined(value) : void 0;
|
|
4037
|
+
return nested === void 0 ? /* @__PURE__ */ new Set() : this.removed(nested);
|
|
4038
|
+
}
|
|
4039
|
+
if (Array.isArray(value)) return union(value.map((v) => this.removed(v)));
|
|
4040
|
+
if (value === null || typeof value !== "object") return /* @__PURE__ */ new Set();
|
|
4041
|
+
return union(
|
|
4042
|
+
Object.entries(value).map(
|
|
4043
|
+
([key2, item]) => this.isSecret(key2) ? leaves(item) : this.removed(item)
|
|
4044
|
+
)
|
|
4045
|
+
);
|
|
4046
|
+
}
|
|
4047
|
+
stripNested(text2) {
|
|
4048
|
+
if (!this.mentions(text2)) return text2;
|
|
4049
|
+
const parsed = jsonOrUndefined(text2);
|
|
4050
|
+
if (parsed === void 0) return text2;
|
|
4051
|
+
return JSON.stringify(this.strip(parsed));
|
|
4052
|
+
}
|
|
4053
|
+
};
|
|
4054
|
+
SPAN_SECRETS = new SpanSecrets();
|
|
4055
|
+
SecretRedactingSpanProcessor = class {
|
|
4056
|
+
constructor(inner, secrets = SPAN_SECRETS) {
|
|
4057
|
+
this.inner = inner;
|
|
4058
|
+
this.secrets = secrets;
|
|
4059
|
+
}
|
|
4060
|
+
inner;
|
|
4061
|
+
secrets;
|
|
4062
|
+
views = /* @__PURE__ */ new WeakMap();
|
|
4063
|
+
onStart(span, parentContext) {
|
|
4064
|
+
this.inner.onStart(this.viewFor(span), parentContext);
|
|
4065
|
+
}
|
|
4066
|
+
onEnd(span) {
|
|
4067
|
+
const view = this.viewFor(span);
|
|
4068
|
+
try {
|
|
4069
|
+
void [view.attributes, view.events, view.status];
|
|
4070
|
+
} catch (error) {
|
|
4071
|
+
console.warn(
|
|
4072
|
+
`[gatewaysdk.tracing] Dropped span "${span.name}": could not redact it: ${error?.name}`
|
|
4073
|
+
);
|
|
4074
|
+
return;
|
|
4075
|
+
}
|
|
4076
|
+
this.inner.onEnd(view);
|
|
4077
|
+
}
|
|
4078
|
+
viewFor(span) {
|
|
4079
|
+
const known = this.views.get(span);
|
|
4080
|
+
if (known) return known;
|
|
4081
|
+
const view = viewOf(span, {
|
|
4082
|
+
attributes: () => this.scrubbedAttributes(span.attributes),
|
|
4083
|
+
events: () => span.events.map((event) => this.scrubbedEvent(event)),
|
|
4084
|
+
status: () => this.scrubbedStatus(span.status)
|
|
4085
|
+
});
|
|
4086
|
+
this.views.set(span, view);
|
|
4087
|
+
return view;
|
|
4088
|
+
}
|
|
4089
|
+
forceFlush() {
|
|
4090
|
+
return this.inner.forceFlush();
|
|
4091
|
+
}
|
|
4092
|
+
shutdown() {
|
|
4093
|
+
return this.inner.shutdown();
|
|
4094
|
+
}
|
|
4095
|
+
scrubbedAttributes(attributes) {
|
|
4096
|
+
const clean = this.secrets.scrubAttributes(attributes);
|
|
4097
|
+
return sameAttributes(attributes, clean) ? attributes : clean;
|
|
4098
|
+
}
|
|
4099
|
+
scrubbedStatus(status) {
|
|
4100
|
+
if (!status.message) return status;
|
|
4101
|
+
const message = this.secrets.scrubAttribute(status.message);
|
|
4102
|
+
return message === status.message ? status : { ...status, message };
|
|
4103
|
+
}
|
|
4104
|
+
scrubbedEvent(event) {
|
|
4105
|
+
if (!event.attributes) return event;
|
|
4106
|
+
const attributes = this.scrubbedAttributes(event.attributes);
|
|
4107
|
+
if (attributes === event.attributes) return event;
|
|
4108
|
+
return { ...event, attributes };
|
|
2560
4109
|
}
|
|
2561
4110
|
};
|
|
2562
4111
|
}
|
|
@@ -2567,7 +4116,7 @@ var require_package = __commonJS({
|
|
|
2567
4116
|
"package.json"(exports, module) {
|
|
2568
4117
|
module.exports = {
|
|
2569
4118
|
name: "@withgateway/sdk",
|
|
2570
|
-
version: "0.
|
|
4119
|
+
version: "0.3.0",
|
|
2571
4120
|
description: "Gateway SDK for TypeScript - A/B experiments, tracing, and observability",
|
|
2572
4121
|
main: "./dist/index.js",
|
|
2573
4122
|
module: "./dist/index.mjs",
|
|
@@ -2767,7 +4316,7 @@ var require_package = __commonJS({
|
|
|
2767
4316
|
});
|
|
2768
4317
|
|
|
2769
4318
|
// src/build/index.ts
|
|
2770
|
-
import { createHash as
|
|
4319
|
+
import { createHash as createHash3 } from "crypto";
|
|
2771
4320
|
function canonicalJson(value) {
|
|
2772
4321
|
if (value === null || typeof value !== "object") {
|
|
2773
4322
|
return JSON.stringify(value);
|
|
@@ -2779,7 +4328,7 @@ function canonicalJson(value) {
|
|
|
2779
4328
|
return `{${entries.map(([k, v]) => `${JSON.stringify(k)}:${canonicalJson(v)}`).join(",")}}`;
|
|
2780
4329
|
}
|
|
2781
4330
|
function sha256(text2) {
|
|
2782
|
-
return `sha256:${
|
|
4331
|
+
return `sha256:${createHash3("sha256").update(text2).digest("hex")}`;
|
|
2783
4332
|
}
|
|
2784
4333
|
function captureSource() {
|
|
2785
4334
|
const stack = new Error().stack?.split("\n") ?? [];
|
|
@@ -3174,7 +4723,7 @@ function buildProvider(config, logFn) {
|
|
|
3174
4723
|
const spanProcessors = [];
|
|
3175
4724
|
if (config.customSpanProcessors) {
|
|
3176
4725
|
for (const sp of config.customSpanProcessors) {
|
|
3177
|
-
spanProcessors.push(sp);
|
|
4726
|
+
spanProcessors.push(new SecretRedactingSpanProcessor(sp));
|
|
3178
4727
|
logFn(
|
|
3179
4728
|
"Added custom span processor: %s",
|
|
3180
4729
|
sp.constructor?.name ?? "unknown"
|
|
@@ -3193,7 +4742,11 @@ function buildProvider(config, logFn) {
|
|
|
3193
4742
|
if (config.batch?.maxExportBatchSize) {
|
|
3194
4743
|
batchConfig.maxExportBatchSize = config.batch.maxExportBatchSize;
|
|
3195
4744
|
}
|
|
3196
|
-
spanProcessors.push(
|
|
4745
|
+
spanProcessors.push(
|
|
4746
|
+
new SecretRedactingSpanProcessor(
|
|
4747
|
+
new BatchSpanProcessor(exporter, batchConfig)
|
|
4748
|
+
)
|
|
4749
|
+
);
|
|
3197
4750
|
let provider = new NodeTracerProvider({
|
|
3198
4751
|
resource: createResource(resourceAttrs)
|
|
3199
4752
|
});
|
|
@@ -3331,7 +4884,8 @@ var init_init = __esm({
|
|
|
3331
4884
|
"src/tracing/init.ts"() {
|
|
3332
4885
|
"use strict";
|
|
3333
4886
|
init_identity();
|
|
3334
|
-
|
|
4887
|
+
init_secrets();
|
|
4888
|
+
init_session();
|
|
3335
4889
|
init_scores();
|
|
3336
4890
|
init_build();
|
|
3337
4891
|
ENV_VARS = {
|
|
@@ -3487,7 +5041,7 @@ async function runTask(ref, agent, opts) {
|
|
|
3487
5041
|
let extra = {};
|
|
3488
5042
|
try {
|
|
3489
5043
|
const invoke = () => agent(taskRun);
|
|
3490
|
-
const result = traced ? await (await Promise.resolve().then(() => (
|
|
5044
|
+
const result = traced ? await (await Promise.resolve().then(() => (init_session(), session_exports))).withSession(runId, invoke) : await invoke();
|
|
3491
5045
|
({ report, extra } = reportFromResult(result));
|
|
3492
5046
|
} catch (error) {
|
|
3493
5047
|
const message = (error instanceof Error ? error.message : String(error)) || "Unknown error";
|
|
@@ -3560,7 +5114,7 @@ var init_taskRun = __esm({
|
|
|
3560
5114
|
"use strict";
|
|
3561
5115
|
init_browser();
|
|
3562
5116
|
init_evals();
|
|
3563
|
-
|
|
5117
|
+
init_session2();
|
|
3564
5118
|
init_taskSessions();
|
|
3565
5119
|
TaskRun = class {
|
|
3566
5120
|
constructor(runId, instruction, model, sessions2, manifest) {
|
|
@@ -3869,7 +5423,7 @@ var init_checkoutTarget = __esm({
|
|
|
3869
5423
|
});
|
|
3870
5424
|
|
|
3871
5425
|
// src/worlds/worldDir.ts
|
|
3872
|
-
import { createHash as
|
|
5426
|
+
import { createHash as createHash4 } from "crypto";
|
|
3873
5427
|
import * as fs3 from "fs";
|
|
3874
5428
|
import * as path3 from "path";
|
|
3875
5429
|
var 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;
|
|
@@ -3979,7 +5533,7 @@ var init_worldDir = __esm({
|
|
|
3979
5533
|
* sorted order: the version's identity, byte-compatible with
|
|
3980
5534
|
* `_archive.compute_content_hash` and Prime Intellect. */
|
|
3981
5535
|
get contentHash() {
|
|
3982
|
-
const hasher =
|
|
5536
|
+
const hasher = createHash4("sha256");
|
|
3983
5537
|
for (const rel of this.archivePaths) {
|
|
3984
5538
|
hasher.update(Buffer.from(`file:${rel}`, "utf-8"));
|
|
3985
5539
|
hasher.update(fs3.readFileSync(path3.join(this.dir, rel)));
|
|
@@ -4175,7 +5729,7 @@ __export(hub_exports, {
|
|
|
4175
5729
|
snapshotTreeHashes: () => snapshotTreeHashes,
|
|
4176
5730
|
writeLocalMeta: () => writeLocalMeta
|
|
4177
5731
|
});
|
|
4178
|
-
import { createHash as
|
|
5732
|
+
import { createHash as createHash5 } from "crypto";
|
|
4179
5733
|
import { gzipSync } from "zlib";
|
|
4180
5734
|
import * as fs5 from "fs";
|
|
4181
5735
|
import * as path5 from "path";
|
|
@@ -4287,7 +5841,7 @@ function writeLocalMeta(dir, meta) {
|
|
|
4287
5841
|
function snapshotTreeHashes(dir) {
|
|
4288
5842
|
const out = {};
|
|
4289
5843
|
for (const relPath of collectArchiveRelPaths(dir)) {
|
|
4290
|
-
out[relPath] =
|
|
5844
|
+
out[relPath] = createHash5("sha256").update(fs5.readFileSync(path5.join(dir, relPath))).digest("hex");
|
|
4291
5845
|
}
|
|
4292
5846
|
return out;
|
|
4293
5847
|
}
|
|
@@ -4333,7 +5887,7 @@ function buildFileManifest(dir) {
|
|
|
4333
5887
|
path: relPath,
|
|
4334
5888
|
isDirectory: false,
|
|
4335
5889
|
size: payload.length,
|
|
4336
|
-
sha256:
|
|
5890
|
+
sha256: createHash5("sha256").update(payload).digest("hex")
|
|
4337
5891
|
};
|
|
4338
5892
|
});
|
|
4339
5893
|
}
|
|
@@ -4558,7 +6112,7 @@ var init_hub = __esm({
|
|
|
4558
6112
|
tracked;
|
|
4559
6113
|
declared;
|
|
4560
6114
|
};
|
|
4561
|
-
sha256b64 = (data) =>
|
|
6115
|
+
sha256b64 = (data) => createHash5("sha256").update(data).digest("base64");
|
|
4562
6116
|
DetachedPushError = class extends Error {
|
|
4563
6117
|
constructor(dir, tag) {
|
|
4564
6118
|
super(
|
|
@@ -5185,7 +6739,7 @@ var init_json = __esm({
|
|
|
5185
6739
|
});
|
|
5186
6740
|
|
|
5187
6741
|
// src/worlds/transforms.ts
|
|
5188
|
-
import { createHash as
|
|
6742
|
+
import { createHash as createHash6 } from "crypto";
|
|
5189
6743
|
function parseTransform(name) {
|
|
5190
6744
|
const simple = Object.prototype.hasOwnProperty.call(SIMPLE, name) ? SIMPLE[name] : void 0;
|
|
5191
6745
|
if (simple) return simple;
|
|
@@ -5223,7 +6777,7 @@ var init_transforms = __esm({
|
|
|
5223
6777
|
return at === -1 ? "" : value.slice(at + 1).toLowerCase();
|
|
5224
6778
|
};
|
|
5225
6779
|
stripPrefix = (prefix) => (value) => value.startsWith(prefix) ? value.slice(prefix.length) : value;
|
|
5226
|
-
hex = (algorithm, value) =>
|
|
6780
|
+
hex = (algorithm, value) => createHash6(algorithm).update(value, "utf8").digest("hex");
|
|
5227
6781
|
SIMPLE = {
|
|
5228
6782
|
lower: (value) => value.toLowerCase(),
|
|
5229
6783
|
upper: (value) => value.toUpperCase(),
|
|
@@ -5247,7 +6801,7 @@ var init_transforms = __esm({
|
|
|
5247
6801
|
});
|
|
5248
6802
|
|
|
5249
6803
|
// src/worlds/redaction.ts
|
|
5250
|
-
import { createHash as
|
|
6804
|
+
import { createHash as createHash7 } from "crypto";
|
|
5251
6805
|
function pyText(value) {
|
|
5252
6806
|
if (typeof value === "string") return value;
|
|
5253
6807
|
if (Number.isInteger(value)) return String(value);
|
|
@@ -5256,7 +6810,7 @@ function pyText(value) {
|
|
|
5256
6810
|
return pyFloatRepr(value);
|
|
5257
6811
|
}
|
|
5258
6812
|
function hashForm(slug, plaintext) {
|
|
5259
|
-
return "sha256:" +
|
|
6813
|
+
return "sha256:" + createHash7("sha256").update(`${slug}:${pyText(plaintext)}`, "utf8").digest("hex");
|
|
5260
6814
|
}
|
|
5261
6815
|
function preserveForm(slug, plaintext) {
|
|
5262
6816
|
const kind = typeof plaintext === "string" ? "str" : isInt(plaintext) ? "int" : "float";
|
|
@@ -5265,12 +6819,12 @@ function preserveForm(slug, plaintext) {
|
|
|
5265
6819
|
}
|
|
5266
6820
|
function shapeText(slug, text2, kind) {
|
|
5267
6821
|
const seed = Buffer.from(`${slug}:${text2}`, "utf8");
|
|
5268
|
-
let digest =
|
|
6822
|
+
let digest = createHash7("sha256").update(seed).digest();
|
|
5269
6823
|
let cursor = 0;
|
|
5270
6824
|
const out = [];
|
|
5271
6825
|
for (const char of text2) {
|
|
5272
6826
|
if (cursor === digest.length) {
|
|
5273
|
-
digest =
|
|
6827
|
+
digest = createHash7("sha256").update(Buffer.concat([digest, seed])).digest();
|
|
5274
6828
|
cursor = 0;
|
|
5275
6829
|
}
|
|
5276
6830
|
const byte = digest[cursor];
|
|
@@ -6169,7 +7723,7 @@ if (fn) {
|
|
|
6169
7723
|
});
|
|
6170
7724
|
|
|
6171
7725
|
// src/cli/platform/worldData/batches.ts
|
|
6172
|
-
import { createHash as
|
|
7726
|
+
import { createHash as createHash8 } from "crypto";
|
|
6173
7727
|
import * as fs11 from "fs";
|
|
6174
7728
|
function isSettled(status) {
|
|
6175
7729
|
if (!TERMINAL_STATES.has(status.state)) return false;
|
|
@@ -6180,7 +7734,7 @@ function uploadHeadersFor(gz) {
|
|
|
6180
7734
|
return {
|
|
6181
7735
|
"content-type": "application/gzip",
|
|
6182
7736
|
"content-length": String(gz.length),
|
|
6183
|
-
"x-amz-checksum-sha256":
|
|
7737
|
+
"x-amz-checksum-sha256": createHash8("sha256").update(gz).digest("base64")
|
|
6184
7738
|
};
|
|
6185
7739
|
}
|
|
6186
7740
|
async function forEachLimited(items, limit, fn) {
|
|
@@ -6383,7 +7937,7 @@ var init_batches = __esm({
|
|
|
6383
7937
|
});
|
|
6384
7938
|
|
|
6385
7939
|
// src/cli/platform/worldData/chunker.ts
|
|
6386
|
-
import { createHash as
|
|
7940
|
+
import { createHash as createHash9 } from "crypto";
|
|
6387
7941
|
import { deflateRawSync } from "zlib";
|
|
6388
7942
|
function chunkLine(row, declared) {
|
|
6389
7943
|
if (declared !== null) return dumps(row.row) + "\n";
|
|
@@ -6424,12 +7978,12 @@ function finishChunk(ordinal, raw, rows, entity, firstRow = 0) {
|
|
|
6424
7978
|
const gz = gzipDeterministic(raw, { name: chunkName(ordinal) });
|
|
6425
7979
|
return {
|
|
6426
7980
|
ordinal,
|
|
6427
|
-
digest:
|
|
7981
|
+
digest: createHash9("sha256").update(gz).digest("hex"),
|
|
6428
7982
|
bytes: gz.length,
|
|
6429
7983
|
rows,
|
|
6430
7984
|
entity,
|
|
6431
7985
|
rawBytes: raw.length,
|
|
6432
|
-
contentSha256:
|
|
7986
|
+
contentSha256: createHash9("sha256").update(raw).digest("hex"),
|
|
6433
7987
|
firstRow,
|
|
6434
7988
|
gz
|
|
6435
7989
|
};
|
|
@@ -6766,7 +8320,7 @@ var init_ingest = __esm({
|
|
|
6766
8320
|
});
|
|
6767
8321
|
|
|
6768
8322
|
// src/worlds/editSessions.ts
|
|
6769
|
-
var WORLDS, WorldEditClient;
|
|
8323
|
+
var WORLDS, WorldEditClient, TASK_EDITS, TaskEditClient;
|
|
6770
8324
|
var init_editSessions = __esm({
|
|
6771
8325
|
"src/worlds/editSessions.ts"() {
|
|
6772
8326
|
"use strict";
|
|
@@ -6798,6 +8352,22 @@ var init_editSessions = __esm({
|
|
|
6798
8352
|
return apiRequest(this.options, "POST", `${WORLDS}/${encodeURIComponent(slug)}/edits/rollback`, input);
|
|
6799
8353
|
}
|
|
6800
8354
|
};
|
|
8355
|
+
TASK_EDITS = "/api/public/world-task-edits";
|
|
8356
|
+
TaskEditClient = class {
|
|
8357
|
+
constructor(options = {}) {
|
|
8358
|
+
this.options = options;
|
|
8359
|
+
}
|
|
8360
|
+
options;
|
|
8361
|
+
status(task) {
|
|
8362
|
+
return apiRequest(this.options, "POST", `${TASK_EDITS}/status`, { task });
|
|
8363
|
+
}
|
|
8364
|
+
close(task, input = {}) {
|
|
8365
|
+
return apiRequest(this.options, "POST", `${TASK_EDITS}/close`, { task, ...input });
|
|
8366
|
+
}
|
|
8367
|
+
rollback(task, input) {
|
|
8368
|
+
return apiRequest(this.options, "POST", `${TASK_EDITS}/rollback`, { task, ...input });
|
|
8369
|
+
}
|
|
8370
|
+
};
|
|
6801
8371
|
}
|
|
6802
8372
|
});
|
|
6803
8373
|
|
|
@@ -6893,6 +8463,10 @@ var init_dryRun = __esm({
|
|
|
6893
8463
|
// src/worlds/index.ts
|
|
6894
8464
|
var worlds_exports = {};
|
|
6895
8465
|
__export(worlds_exports, {
|
|
8466
|
+
ACTION_NAMES: () => ACTION_NAMES,
|
|
8467
|
+
ActionTracer: () => ActionTracer,
|
|
8468
|
+
AnthropicComputer: () => AnthropicComputer,
|
|
8469
|
+
AnthropicComputer20251124: () => AnthropicComputer20251124,
|
|
6896
8470
|
ApiError: () => ApiError,
|
|
6897
8471
|
BROWSER_GONE_PATTERNS: () => BROWSER_GONE_PATTERNS,
|
|
6898
8472
|
BROWSER_TIERS: () => BROWSER_TIERS,
|
|
@@ -6904,11 +8478,13 @@ __export(worlds_exports, {
|
|
|
6904
8478
|
CALL_BODY_LIMIT_LABEL: () => CALL_BODY_LIMIT_LABEL,
|
|
6905
8479
|
COMPUTER_USE_SPECS: () => COMPUTER_USE_SPECS,
|
|
6906
8480
|
CheckoutProvenance: () => CheckoutProvenance,
|
|
8481
|
+
ComputerAction: () => ComputerAction,
|
|
6907
8482
|
DEFAULT_BRANCH: () => DEFAULT_BRANCH,
|
|
6908
8483
|
DEFAULT_VIEWPORT: () => DEFAULT_VIEWPORT,
|
|
6909
8484
|
DRY_RUN_AGENT: () => DRY_RUN_AGENT,
|
|
6910
8485
|
DRY_RUN_KIND: () => DRY_RUN_KIND,
|
|
6911
8486
|
DetachedPushError: () => DetachedPushError,
|
|
8487
|
+
Display: () => Display,
|
|
6912
8488
|
DryRunOutcome: () => DryRunOutcome,
|
|
6913
8489
|
EVENT_BATCH_SIZE: () => EVENT_BATCH_SIZE,
|
|
6914
8490
|
EVENT_FLUSH_INTERVAL_MS: () => EVENT_FLUSH_INTERVAL_MS,
|
|
@@ -6918,19 +8494,30 @@ __export(worlds_exports, {
|
|
|
6918
8494
|
GatewayEvalsClient: () => GatewayEvalsClient,
|
|
6919
8495
|
HostedDryRunClient: () => HostedDryRunClient,
|
|
6920
8496
|
IDLE_WARNING_MINUTES: () => IDLE_WARNING_MINUTES,
|
|
8497
|
+
KEY_NAMES: () => KEY_NAMES,
|
|
8498
|
+
KeyChord: () => KeyChord,
|
|
8499
|
+
NOT_EXECUTED: () => NOT_EXECUTED,
|
|
6921
8500
|
NO_GRADER_REASON: () => NO_GRADER_REASON,
|
|
8501
|
+
NativeComputer: () => NativeComputer,
|
|
8502
|
+
OpenAIComputer: () => OpenAIComputer,
|
|
8503
|
+
OpenAIPreviewComputer: () => OpenAIPreviewComputer,
|
|
6922
8504
|
PLATFORM_TIMEOUT_DEFAULT_MS: () => PLATFORM_TIMEOUT_DEFAULT_MS,
|
|
6923
8505
|
PLATFORM_TIMEOUT_ENV: () => PLATFORM_TIMEOUT_ENV,
|
|
8506
|
+
PendingSafetyChecks: () => PendingSafetyChecks,
|
|
6924
8507
|
PlatformTransport: () => PlatformTransport,
|
|
6925
8508
|
PushSlugConflict: () => PushSlugConflict,
|
|
6926
8509
|
RECOVER_BUDGET_MS: () => RECOVER_BUDGET_MS,
|
|
6927
8510
|
SANDBOX_REQUEST_TIMEOUT_MS: () => SANDBOX_REQUEST_TIMEOUT_MS,
|
|
8511
|
+
SECRET_KEY: () => SECRET_KEY,
|
|
6928
8512
|
SESSION_STATES: () => SESSION_STATES,
|
|
8513
|
+
SPAN_PREFIX: () => SPAN_PREFIX,
|
|
6929
8514
|
STATUS_WAIT_CAP_SECONDS: () => STATUS_WAIT_CAP_SECONDS,
|
|
6930
8515
|
STRIP_PREFIX: () => STRIP_PREFIX,
|
|
6931
8516
|
SURFACE_KINDS: () => SURFACE_KINDS,
|
|
8517
|
+
Screen: () => Screen,
|
|
6932
8518
|
SecretScrubber: () => SecretScrubber,
|
|
6933
8519
|
TRANSFORMS: () => TRANSFORMS,
|
|
8520
|
+
TaskEditClient: () => TaskEditClient,
|
|
6934
8521
|
TaskRun: () => TaskRun,
|
|
6935
8522
|
TaskSessions: () => TaskSessions,
|
|
6936
8523
|
TransportCause: () => TransportCause,
|
|
@@ -7003,6 +8590,7 @@ __export(worlds_exports, {
|
|
|
7003
8590
|
parseTransform: () => parseTransform,
|
|
7004
8591
|
parseWorldTaskRefs: () => parseWorldTaskRefs,
|
|
7005
8592
|
platformTimeoutMs: () => platformTimeoutMs,
|
|
8593
|
+
playwrightKey: () => playwrightKey,
|
|
7006
8594
|
preserveForm: () => preserveForm,
|
|
7007
8595
|
propose: () => propose,
|
|
7008
8596
|
pull: () => pull,
|
|
@@ -7012,6 +8600,7 @@ __export(worlds_exports, {
|
|
|
7012
8600
|
pyText: () => pyText,
|
|
7013
8601
|
queryRows: () => queryRows,
|
|
7014
8602
|
queryRowsSearch: () => queryRowsSearch,
|
|
8603
|
+
readField: () => readField,
|
|
7015
8604
|
readLocalMeta: () => readLocalMeta,
|
|
7016
8605
|
readToolCallRecords: () => readToolCallRecords,
|
|
7017
8606
|
rebaseConflicts: () => rebaseConflicts,
|
|
@@ -7261,7 +8850,7 @@ var init_worlds = __esm({
|
|
|
7261
8850
|
"use strict";
|
|
7262
8851
|
init_transport();
|
|
7263
8852
|
init_transport();
|
|
7264
|
-
|
|
8853
|
+
init_session2();
|
|
7265
8854
|
init_sessionList();
|
|
7266
8855
|
init_sessionContract();
|
|
7267
8856
|
init_taskRef();
|
|
@@ -7273,6 +8862,7 @@ var init_worlds = __esm({
|
|
|
7273
8862
|
init_evals();
|
|
7274
8863
|
init_browser();
|
|
7275
8864
|
init_browserReconnect();
|
|
8865
|
+
init_nativeComputer();
|
|
7276
8866
|
init_hub();
|
|
7277
8867
|
init_validate();
|
|
7278
8868
|
init_describe();
|
|
@@ -7339,7 +8929,7 @@ var init_worlds = __esm({
|
|
|
7339
8929
|
* worlds/session.ts.
|
|
7340
8930
|
*/
|
|
7341
8931
|
async open(task, opts = {}) {
|
|
7342
|
-
const { openSession: openSession2 } = await Promise.resolve().then(() => (
|
|
8932
|
+
const { openSession: openSession2 } = await Promise.resolve().then(() => (init_session2(), session_exports2));
|
|
7343
8933
|
return openSession2(this.slug, {
|
|
7344
8934
|
task,
|
|
7345
8935
|
versionId: this.version.versionId,
|
|
@@ -9764,7 +11354,7 @@ var gateway = {
|
|
|
9764
11354
|
init_users();
|
|
9765
11355
|
init_scores();
|
|
9766
11356
|
init_worlds();
|
|
9767
|
-
|
|
11357
|
+
init_session2();
|
|
9768
11358
|
|
|
9769
11359
|
// src/files/index.ts
|
|
9770
11360
|
var files_exports = {};
|
|
@@ -9791,7 +11381,7 @@ __export(files_exports, {
|
|
|
9791
11381
|
uploadFile: () => uploadFile
|
|
9792
11382
|
});
|
|
9793
11383
|
init_worlds();
|
|
9794
|
-
import { createHash as
|
|
11384
|
+
import { createHash as createHash10 } from "crypto";
|
|
9795
11385
|
import * as fs13 from "fs";
|
|
9796
11386
|
import * as path12 from "path";
|
|
9797
11387
|
import { Readable, Transform } from "stream";
|
|
@@ -9856,7 +11446,7 @@ async function confirmUpload(options = {}, fileId, ok = true) {
|
|
|
9856
11446
|
return apiRequest(options, "POST", `${BASE}/confirm`, { fileId, ok });
|
|
9857
11447
|
}
|
|
9858
11448
|
async function sha256Base64(localPath) {
|
|
9859
|
-
const hash =
|
|
11449
|
+
const hash = createHash10("sha256");
|
|
9860
11450
|
for await (const chunk of fs13.createReadStream(localPath)) hash.update(chunk);
|
|
9861
11451
|
return hash.digest("base64");
|
|
9862
11452
|
}
|
|
@@ -9941,7 +11531,7 @@ async function uploadBytes(options = {}, bytes, targetPath, upload = {}) {
|
|
|
9941
11531
|
if (!bytes.length) throw new Error("nothing to upload: the content is empty");
|
|
9942
11532
|
const target = drivePath(targetPath);
|
|
9943
11533
|
const contentType = upload.contentType ?? contentTypeFor(target);
|
|
9944
|
-
const sha2562 =
|
|
11534
|
+
const sha2562 = createHash10("sha256").update(bytes).digest("base64");
|
|
9945
11535
|
const granted = await requestUpload(options, { path: target, contentLength: bytes.length, contentType, sha256: sha2562, ...upload.overwrite ? { overwrite: true } : {} });
|
|
9946
11536
|
try {
|
|
9947
11537
|
await putPresigned(granted.uploadUrl, new Uint8Array(bytes), { contentType, contentLength: bytes.length, sha256: sha2562 });
|
|
@@ -10194,10 +11784,10 @@ function swapValue(text2, needle, replacement) {
|
|
|
10194
11784
|
}
|
|
10195
11785
|
|
|
10196
11786
|
// src/hooks/standInDigits.ts
|
|
10197
|
-
import { createHash as
|
|
11787
|
+
import { createHash as createHash11 } from "crypto";
|
|
10198
11788
|
function standInDigits(realDigits, identityName) {
|
|
10199
11789
|
if (!realDigits) return "";
|
|
10200
|
-
const digest =
|
|
11790
|
+
const digest = createHash11("sha256").update(`${identityName}:${realDigits}`).digest("hex");
|
|
10201
11791
|
let digits = "";
|
|
10202
11792
|
for (let i = 0; i < realDigits.length; i++)
|
|
10203
11793
|
digits += String(parseInt(digest[i % digest.length], 16) % 10);
|
|
@@ -10231,7 +11821,7 @@ var DeclaredStandIn = class _DeclaredStandIn {
|
|
|
10231
11821
|
};
|
|
10232
11822
|
|
|
10233
11823
|
// src/hooks/alias.ts
|
|
10234
|
-
import { createHash as
|
|
11824
|
+
import { createHash as createHash12, createHmac, randomBytes as randomBytes2 } from "crypto";
|
|
10235
11825
|
var GIVEN = [
|
|
10236
11826
|
"John",
|
|
10237
11827
|
"Mary",
|
|
@@ -10503,7 +12093,7 @@ function nameParts(name) {
|
|
|
10503
12093
|
function format(template, parts2) {
|
|
10504
12094
|
return template.replace(/\{(\w+)\}/g, (_, key2) => parts2[key2] ?? "").trim();
|
|
10505
12095
|
}
|
|
10506
|
-
var
|
|
12096
|
+
var pair2 = (real, fake, template) => [
|
|
10507
12097
|
format(template, real),
|
|
10508
12098
|
format(template, fake)
|
|
10509
12099
|
];
|
|
@@ -10563,7 +12153,7 @@ function namePairs(real, fake) {
|
|
|
10563
12153
|
const out = [[real, fake]];
|
|
10564
12154
|
if (realParts.given && realParts.surname) {
|
|
10565
12155
|
for (const template of NAME_FORMS) {
|
|
10566
|
-
const p =
|
|
12156
|
+
const p = pair2(realParts, fakeParts, template);
|
|
10567
12157
|
if (p[0].length > 2 && !p[0].includes("{")) out.push(p);
|
|
10568
12158
|
}
|
|
10569
12159
|
}
|
|
@@ -10601,7 +12191,7 @@ function emailPairs(real, fake) {
|
|
|
10601
12191
|
};
|
|
10602
12192
|
const out = [[real, fake]];
|
|
10603
12193
|
for (const template of EMAIL_FORMS) {
|
|
10604
|
-
const p =
|
|
12194
|
+
const p = pair2(realParts, fakeParts, template);
|
|
10605
12195
|
if (p[0].length > 2) out.push(p);
|
|
10606
12196
|
}
|
|
10607
12197
|
return dedupe(out);
|
|
@@ -11052,9 +12642,9 @@ var AliasMap = class _AliasMap {
|
|
|
11052
12642
|
});
|
|
11053
12643
|
if (alias.role === "private") {
|
|
11054
12644
|
for (const slug of this.slugs) {
|
|
11055
|
-
const standIn = "sha256:" +
|
|
12645
|
+
const standIn = "sha256:" + createHash12("sha256").update(`${slug}:${canonical(alias.kind, alias.display)}`, "utf8").digest("hex");
|
|
11056
12646
|
alias.variants.push([
|
|
11057
|
-
"sha256:" +
|
|
12647
|
+
"sha256:" + createHash12("sha256").update(`${slug}:${alias.canonical}`, "utf8").digest("hex"),
|
|
11058
12648
|
standIn
|
|
11059
12649
|
]);
|
|
11060
12650
|
this.aliasDigests.add(standIn.toLowerCase());
|
|
@@ -11869,7 +13459,7 @@ function inputSchema(shorthand, position) {
|
|
|
11869
13459
|
`${position}.input: expected a table of field = "type"`
|
|
11870
13460
|
);
|
|
11871
13461
|
const properties = {};
|
|
11872
|
-
const
|
|
13462
|
+
const required2 = [];
|
|
11873
13463
|
for (const [name, raw] of Object.entries(shorthand)) {
|
|
11874
13464
|
if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(name))
|
|
11875
13465
|
throw new HookConfigError(
|
|
@@ -11903,9 +13493,9 @@ function inputSchema(shorthand, position) {
|
|
|
11903
13493
|
`${position}.input.${name}: expected "type" or a schema table`
|
|
11904
13494
|
);
|
|
11905
13495
|
properties[name] = schema;
|
|
11906
|
-
if (!optional)
|
|
13496
|
+
if (!optional) required2.push(name);
|
|
11907
13497
|
}
|
|
11908
|
-
return { type: "object", properties, required };
|
|
13498
|
+
return { type: "object", properties, required: required2 };
|
|
11909
13499
|
}
|
|
11910
13500
|
function placeholders(value) {
|
|
11911
13501
|
if (typeof value === "string")
|
|
@@ -14729,11 +16319,20 @@ init_identity();
|
|
|
14729
16319
|
var tracing_exports = {};
|
|
14730
16320
|
__export(tracing_exports, {
|
|
14731
16321
|
IdentitySpanProcessor: () => IdentitySpanProcessor,
|
|
16322
|
+
MAX_MEDIA_BYTES: () => MAX_MEDIA_BYTES,
|
|
16323
|
+
MediaReference: () => MediaReference,
|
|
16324
|
+
MediaUploadError: () => MediaUploadError,
|
|
16325
|
+
MediaUploader: () => MediaUploader,
|
|
16326
|
+
SECRET_KEYS: () => SECRET_KEYS,
|
|
14732
16327
|
SESSION_ID_ATTRIBUTE: () => SESSION_ID_ATTRIBUTE,
|
|
16328
|
+
SecretRedactingSpanProcessor: () => SecretRedactingSpanProcessor,
|
|
14733
16329
|
SessionSpanProcessor: () => SessionSpanProcessor,
|
|
16330
|
+
SpanSecrets: () => SpanSecrets,
|
|
14734
16331
|
USER_ID_ATTRIBUTE: () => USER_ID_ATTRIBUTE,
|
|
16332
|
+
WORLD_SESSION_ID_ATTRIBUTE: () => WORLD_SESSION_ID_ATTRIBUTE,
|
|
14735
16333
|
flush: () => flush,
|
|
14736
16334
|
getAmbientSessionId: () => getAmbientSessionId,
|
|
16335
|
+
getCurrentWorldSessionId: () => getCurrentWorldSessionId,
|
|
14737
16336
|
identify: () => identify,
|
|
14738
16337
|
init: () => init2,
|
|
14739
16338
|
initIsolated: () => initIsolated,
|
|
@@ -14746,11 +16345,13 @@ __export(tracing_exports, {
|
|
|
14746
16345
|
resetAmbientUser: () => resetAmbientUser,
|
|
14747
16346
|
resolveUserId: () => resolveUserId,
|
|
14748
16347
|
shutdown: () => shutdown2,
|
|
14749
|
-
withSession: () => withSession
|
|
16348
|
+
withSession: () => withSession,
|
|
16349
|
+
withWorldSession: () => withWorldSession
|
|
14750
16350
|
});
|
|
14751
16351
|
init_init();
|
|
14752
16352
|
init_identity();
|
|
14753
|
-
|
|
16353
|
+
init_session();
|
|
16354
|
+
init_secrets();
|
|
14754
16355
|
|
|
14755
16356
|
// src/tracing/observe.ts
|
|
14756
16357
|
import { trace as trace3, context as context2, SpanStatusCode } from "@opentelemetry/api";
|
|
@@ -15013,6 +16614,9 @@ async function* observeClaude(stream, options) {
|
|
|
15013
16614
|
}
|
|
15014
16615
|
}
|
|
15015
16616
|
|
|
16617
|
+
// src/tracing/index.ts
|
|
16618
|
+
init_media();
|
|
16619
|
+
|
|
15016
16620
|
// src/index.ts
|
|
15017
16621
|
var tracing = {
|
|
15018
16622
|
...tracing_exports,
|
|
@@ -15031,7 +16635,11 @@ var tracing = {
|
|
|
15031
16635
|
}
|
|
15032
16636
|
};
|
|
15033
16637
|
export {
|
|
16638
|
+
ACTION_NAMES,
|
|
15034
16639
|
AGENT_ID_KEY,
|
|
16640
|
+
ActionTracer,
|
|
16641
|
+
AnthropicComputer,
|
|
16642
|
+
AnthropicComputer20251124,
|
|
15035
16643
|
ApiError,
|
|
15036
16644
|
BROWSER_GONE_PATTERNS,
|
|
15037
16645
|
BROWSER_TIERS,
|
|
@@ -15043,12 +16651,14 @@ export {
|
|
|
15043
16651
|
CALL_BODY_LIMIT_LABEL,
|
|
15044
16652
|
COMPUTER_USE_SPECS,
|
|
15045
16653
|
CheckoutProvenance,
|
|
16654
|
+
ComputerAction,
|
|
15046
16655
|
DEFAULT_BRANCH,
|
|
15047
16656
|
DEFAULT_TIMEOUT_SECONDS,
|
|
15048
16657
|
DEFAULT_VIEWPORT,
|
|
15049
16658
|
DRY_RUN_AGENT,
|
|
15050
16659
|
DRY_RUN_KIND,
|
|
15051
16660
|
DetachedPushError,
|
|
16661
|
+
Display,
|
|
15052
16662
|
DriftError,
|
|
15053
16663
|
DryRunOutcome,
|
|
15054
16664
|
ENV_GATEWAY_HOST,
|
|
@@ -15076,9 +16686,16 @@ export {
|
|
|
15076
16686
|
GatewayToolBlockedError,
|
|
15077
16687
|
HostedDryRunClient,
|
|
15078
16688
|
IDLE_WARNING_MINUTES,
|
|
16689
|
+
KEY_NAMES,
|
|
16690
|
+
KeyChord,
|
|
16691
|
+
NOT_EXECUTED,
|
|
15079
16692
|
NO_GRADER_REASON,
|
|
16693
|
+
NativeComputer,
|
|
16694
|
+
OpenAIComputer,
|
|
16695
|
+
OpenAIPreviewComputer,
|
|
15080
16696
|
PLATFORM_TIMEOUT_DEFAULT_MS,
|
|
15081
16697
|
PLATFORM_TIMEOUT_ENV,
|
|
16698
|
+
PendingSafetyChecks,
|
|
15082
16699
|
Persona,
|
|
15083
16700
|
PersonaError,
|
|
15084
16701
|
PersonasClient,
|
|
@@ -15093,7 +16710,9 @@ export {
|
|
|
15093
16710
|
ReplaySuite,
|
|
15094
16711
|
ReplayTask,
|
|
15095
16712
|
SANDBOX_REQUEST_TIMEOUT_MS,
|
|
16713
|
+
SECRET_KEY,
|
|
15096
16714
|
SESSION_STATES,
|
|
16715
|
+
SPAN_PREFIX,
|
|
15097
16716
|
STATUS_WAIT_CAP_SECONDS,
|
|
15098
16717
|
STRIP_PREFIX,
|
|
15099
16718
|
SUCCESS_METRIC_NAME_KEY,
|
|
@@ -15101,12 +16720,14 @@ export {
|
|
|
15101
16720
|
SURFACE_KINDS,
|
|
15102
16721
|
ScoreError,
|
|
15103
16722
|
ScoresClient,
|
|
16723
|
+
Screen,
|
|
15104
16724
|
SecretScrubber,
|
|
15105
16725
|
SessionLoadError,
|
|
15106
16726
|
SessionRecording,
|
|
15107
16727
|
SessionTrace,
|
|
15108
16728
|
StubMissError,
|
|
15109
16729
|
TRANSFORMS,
|
|
16730
|
+
TaskEditClient,
|
|
15110
16731
|
TaskRun,
|
|
15111
16732
|
TaskSessions,
|
|
15112
16733
|
ToolStubRegistry,
|
|
@@ -15208,6 +16829,7 @@ export {
|
|
|
15208
16829
|
parseWorldTaskRefs,
|
|
15209
16830
|
personas,
|
|
15210
16831
|
platformTimeoutMs,
|
|
16832
|
+
playwrightKey,
|
|
15211
16833
|
preserveForm,
|
|
15212
16834
|
propose,
|
|
15213
16835
|
pull,
|
|
@@ -15217,6 +16839,7 @@ export {
|
|
|
15217
16839
|
pyText,
|
|
15218
16840
|
queryRows,
|
|
15219
16841
|
queryRowsSearch,
|
|
16842
|
+
readField,
|
|
15220
16843
|
readLocalMeta,
|
|
15221
16844
|
readToolCallRecords,
|
|
15222
16845
|
rebaseConflicts,
|