@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.js
CHANGED
|
@@ -756,7 +756,7 @@ function withoutUiToken(url) {
|
|
|
756
756
|
const [beforeHash, hash] = splitHash(url);
|
|
757
757
|
const q = beforeHash.indexOf("?");
|
|
758
758
|
if (q < 0) return url;
|
|
759
|
-
const kept = beforeHash.slice(q + 1).split("&").filter((
|
|
759
|
+
const kept = beforeHash.slice(q + 1).split("&").filter((pair3) => pair3 !== "" && pair3.split("=")[0] !== UI_TOKEN_QUERY);
|
|
760
760
|
return beforeHash.slice(0, q) + (kept.length ? `?${kept.join("&")}` : "") + hash;
|
|
761
761
|
}
|
|
762
762
|
function splitHash(url) {
|
|
@@ -891,7 +891,7 @@ var SURFACE_KINDS, BROWSER_TIERS, DEFAULT_VIEWPORT, SETTLE_TIMEOUT_MS, SETTLE_QU
|
|
|
891
891
|
var init_browser = __esm({
|
|
892
892
|
"src/worlds/browser.ts"() {
|
|
893
893
|
"use strict";
|
|
894
|
-
|
|
894
|
+
init_session2();
|
|
895
895
|
init_browserReconnect();
|
|
896
896
|
SURFACE_KINDS = ["tools", "api", "ui", "browser"];
|
|
897
897
|
BROWSER_TIERS = ["standard", "premium"];
|
|
@@ -1037,6 +1037,10 @@ var init_browser = __esm({
|
|
|
1037
1037
|
get agentId() {
|
|
1038
1038
|
return this.recorder?.agentId ?? null;
|
|
1039
1039
|
}
|
|
1040
|
+
/** `text` with this session's credentials (UI token, browser address) removed. */
|
|
1041
|
+
scrub(text2) {
|
|
1042
|
+
return this.scrubber.scrub(text2);
|
|
1043
|
+
}
|
|
1040
1044
|
watchNetwork(page) {
|
|
1041
1045
|
page.on("request", () => {
|
|
1042
1046
|
this.inflight += 1;
|
|
@@ -1323,6 +1327,1269 @@ var init_browser = __esm({
|
|
|
1323
1327
|
}
|
|
1324
1328
|
});
|
|
1325
1329
|
|
|
1330
|
+
// src/worlds/nativeComputer/actions.ts
|
|
1331
|
+
function toNumber(value) {
|
|
1332
|
+
if (typeof value !== "number" || !Number.isFinite(value))
|
|
1333
|
+
throw new Error(`not a number: ${JSON.stringify(value) ?? String(value)}`);
|
|
1334
|
+
return value;
|
|
1335
|
+
}
|
|
1336
|
+
function toInt(value) {
|
|
1337
|
+
return Math.trunc(toNumber(value));
|
|
1338
|
+
}
|
|
1339
|
+
var ACTION_NAMES, SECRET_TEXT, BOUNDS, ComputerAction;
|
|
1340
|
+
var init_actions = __esm({
|
|
1341
|
+
"src/worlds/nativeComputer/actions.ts"() {
|
|
1342
|
+
"use strict";
|
|
1343
|
+
ACTION_NAMES = [
|
|
1344
|
+
"screenshot",
|
|
1345
|
+
"zoom",
|
|
1346
|
+
"click",
|
|
1347
|
+
"move",
|
|
1348
|
+
"mouse_down",
|
|
1349
|
+
"mouse_up",
|
|
1350
|
+
"drag",
|
|
1351
|
+
"scroll",
|
|
1352
|
+
"type",
|
|
1353
|
+
"key",
|
|
1354
|
+
"hold_key",
|
|
1355
|
+
"wait",
|
|
1356
|
+
"cursor_position",
|
|
1357
|
+
"history"
|
|
1358
|
+
];
|
|
1359
|
+
SECRET_TEXT = "[redacted]";
|
|
1360
|
+
BOUNDS = {
|
|
1361
|
+
seconds: [0, 300],
|
|
1362
|
+
repeat: [1, 100],
|
|
1363
|
+
count: [1, 3],
|
|
1364
|
+
dx: [-1e4, 1e4],
|
|
1365
|
+
dy: [-1e4, 1e4]
|
|
1366
|
+
};
|
|
1367
|
+
ComputerAction = class {
|
|
1368
|
+
constructor(name, args = {}) {
|
|
1369
|
+
this.name = name;
|
|
1370
|
+
this.args = args;
|
|
1371
|
+
if (!ACTION_NAMES.includes(name))
|
|
1372
|
+
throw new Error(`unknown computer action: ${name}`);
|
|
1373
|
+
for (const [key2, [low, high]] of Object.entries(BOUNDS)) {
|
|
1374
|
+
const value = args[key2];
|
|
1375
|
+
if (value !== void 0 && !(Number(value) >= low && Number(value) <= high))
|
|
1376
|
+
throw new Error(
|
|
1377
|
+
`${name} ${key2} must be between ${low} and ${high}, got ${String(value)}`
|
|
1378
|
+
);
|
|
1379
|
+
}
|
|
1380
|
+
}
|
|
1381
|
+
name;
|
|
1382
|
+
args;
|
|
1383
|
+
/** Flat arguments for the browser timeline and the trace: lists become
|
|
1384
|
+
* `"x,y"` strings, and typed text is withheld when it went into a
|
|
1385
|
+
* credential field. */
|
|
1386
|
+
recordArgs(secretText) {
|
|
1387
|
+
const out = {};
|
|
1388
|
+
for (const [key2, value] of Object.entries(this.args))
|
|
1389
|
+
out[key2] = Array.isArray(value) ? value.flat().join(",") : value;
|
|
1390
|
+
if (secretText && "text" in out) out.text = SECRET_TEXT;
|
|
1391
|
+
return out;
|
|
1392
|
+
}
|
|
1393
|
+
};
|
|
1394
|
+
}
|
|
1395
|
+
});
|
|
1396
|
+
|
|
1397
|
+
// src/worlds/nativeComputer/display.ts
|
|
1398
|
+
var FIT_STEP, Display;
|
|
1399
|
+
var init_display = __esm({
|
|
1400
|
+
"src/worlds/nativeComputer/display.ts"() {
|
|
1401
|
+
"use strict";
|
|
1402
|
+
FIT_STEP = 0.98;
|
|
1403
|
+
Display = class _Display {
|
|
1404
|
+
constructor(width, height, viewportWidth, viewportHeight) {
|
|
1405
|
+
this.width = width;
|
|
1406
|
+
this.height = height;
|
|
1407
|
+
this.viewportWidth = viewportWidth;
|
|
1408
|
+
this.viewportHeight = viewportHeight;
|
|
1409
|
+
}
|
|
1410
|
+
width;
|
|
1411
|
+
height;
|
|
1412
|
+
viewportWidth;
|
|
1413
|
+
viewportHeight;
|
|
1414
|
+
/** `size` when the caller names one; otherwise the largest downscale of the
|
|
1415
|
+
* viewport (at most 1:1) that `fits` the provider's limits. */
|
|
1416
|
+
static forViewport(viewport, size, fits = () => true) {
|
|
1417
|
+
const { width, height } = viewport;
|
|
1418
|
+
if (size) return _Display.sized(size[0], size[1], width, height);
|
|
1419
|
+
let scale = 1;
|
|
1420
|
+
while (!fits(Math.round(width * scale), Math.round(height * scale)))
|
|
1421
|
+
scale *= FIT_STEP;
|
|
1422
|
+
return new _Display(
|
|
1423
|
+
Math.round(width * scale),
|
|
1424
|
+
Math.round(height * scale),
|
|
1425
|
+
width,
|
|
1426
|
+
height
|
|
1427
|
+
);
|
|
1428
|
+
}
|
|
1429
|
+
/** A caller's display keeps the viewport's shape: screenshots are scaled
|
|
1430
|
+
* uniformly, so another aspect ratio would map clicks off the image. */
|
|
1431
|
+
static sized(width, height, viewportWidth, viewportHeight) {
|
|
1432
|
+
if (width <= 0 || height <= 0)
|
|
1433
|
+
throw new Error(`display ${width}x${height} must be positive`);
|
|
1434
|
+
const sameShape = width * viewportHeight / viewportWidth;
|
|
1435
|
+
if (Math.abs(sameShape - height) > 1)
|
|
1436
|
+
throw new Error(
|
|
1437
|
+
`display ${width}x${height} must keep the viewport's aspect ratio (${viewportWidth}x${viewportHeight}); try ${width}x${Math.round(sameShape)}`
|
|
1438
|
+
);
|
|
1439
|
+
return new _Display(width, height, viewportWidth, viewportHeight);
|
|
1440
|
+
}
|
|
1441
|
+
get scaled() {
|
|
1442
|
+
return this.width !== this.viewportWidth || this.height !== this.viewportHeight;
|
|
1443
|
+
}
|
|
1444
|
+
get scale() {
|
|
1445
|
+
return Math.min(
|
|
1446
|
+
this.width / this.viewportWidth,
|
|
1447
|
+
this.height / this.viewportHeight
|
|
1448
|
+
);
|
|
1449
|
+
}
|
|
1450
|
+
toPage(x, y) {
|
|
1451
|
+
return [
|
|
1452
|
+
x * this.viewportWidth / this.width,
|
|
1453
|
+
y * this.viewportHeight / this.height
|
|
1454
|
+
];
|
|
1455
|
+
}
|
|
1456
|
+
};
|
|
1457
|
+
}
|
|
1458
|
+
});
|
|
1459
|
+
|
|
1460
|
+
// src/worlds/nativeComputer/screen.ts
|
|
1461
|
+
function pngWidth(png) {
|
|
1462
|
+
if (png.length < 24 || !png.subarray(0, 8).equals(PNG_SIGNATURE)) return null;
|
|
1463
|
+
return png.readUInt32BE(16);
|
|
1464
|
+
}
|
|
1465
|
+
function isNativePage(page) {
|
|
1466
|
+
const candidate = page;
|
|
1467
|
+
const mouse = candidate?.mouse;
|
|
1468
|
+
return typeof candidate?.context === "function" && NATIVE_METHODS.every((m) => typeof mouse?.[m] === "function");
|
|
1469
|
+
}
|
|
1470
|
+
var FOCUSED_FIELD_JS, SECRET_FOCUS, DRAG_STEPS, PNG_SIGNATURE, NATIVE_METHODS, Screen;
|
|
1471
|
+
var init_screen = __esm({
|
|
1472
|
+
"src/worlds/nativeComputer/screen.ts"() {
|
|
1473
|
+
"use strict";
|
|
1474
|
+
init_browser();
|
|
1475
|
+
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(' '); })()";
|
|
1476
|
+
SECRET_FOCUS = ["password", "frame", "opaque"];
|
|
1477
|
+
DRAG_STEPS = 5;
|
|
1478
|
+
PNG_SIGNATURE = Buffer.from([
|
|
1479
|
+
137,
|
|
1480
|
+
80,
|
|
1481
|
+
78,
|
|
1482
|
+
71,
|
|
1483
|
+
13,
|
|
1484
|
+
10,
|
|
1485
|
+
26,
|
|
1486
|
+
10
|
|
1487
|
+
]);
|
|
1488
|
+
NATIVE_METHODS = ["move", "click", "down", "up", "wheel"];
|
|
1489
|
+
Screen = class {
|
|
1490
|
+
constructor(browser, display) {
|
|
1491
|
+
this.browser = browser;
|
|
1492
|
+
this.display = display;
|
|
1493
|
+
}
|
|
1494
|
+
browser;
|
|
1495
|
+
display;
|
|
1496
|
+
cursor = [0, 0];
|
|
1497
|
+
pixelRatio = 1;
|
|
1498
|
+
handlers = {
|
|
1499
|
+
screenshot: async () => ({ image: await this.screenshot() }),
|
|
1500
|
+
zoom: (a) => this.zoom(a),
|
|
1501
|
+
click: (a) => this.click(a),
|
|
1502
|
+
move: (a) => this.held(a.args.modifiers ?? [], () => this.moveTo(this.point(a))),
|
|
1503
|
+
mouse_down: async (a) => {
|
|
1504
|
+
await this.page.mouse.down({ button: a.args.button ?? "left" });
|
|
1505
|
+
return {};
|
|
1506
|
+
},
|
|
1507
|
+
mouse_up: async (a) => {
|
|
1508
|
+
await this.page.mouse.up({ button: a.args.button ?? "left" });
|
|
1509
|
+
return {};
|
|
1510
|
+
},
|
|
1511
|
+
drag: (a) => this.drag(a),
|
|
1512
|
+
scroll: (a) => this.scroll(a),
|
|
1513
|
+
type: async (a) => {
|
|
1514
|
+
await this.page.keyboard.type(a.args.text ?? "");
|
|
1515
|
+
return {};
|
|
1516
|
+
},
|
|
1517
|
+
key: (a) => this.key(a),
|
|
1518
|
+
hold_key: (a) => this.held(
|
|
1519
|
+
a.args.keys ?? [],
|
|
1520
|
+
() => this.page.waitForTimeout((a.args.seconds ?? 0) * 1e3)
|
|
1521
|
+
),
|
|
1522
|
+
wait: async (a) => {
|
|
1523
|
+
await this.page.waitForTimeout((a.args.seconds ?? 0) * 1e3);
|
|
1524
|
+
return {};
|
|
1525
|
+
},
|
|
1526
|
+
cursor_position: async () => ({
|
|
1527
|
+
text: `X=${this.cursor[0]}, Y=${this.cursor[1]}`
|
|
1528
|
+
}),
|
|
1529
|
+
history: async (a) => {
|
|
1530
|
+
const navigate = {
|
|
1531
|
+
back: () => this.page.goBack(),
|
|
1532
|
+
forward: () => this.page.goForward()
|
|
1533
|
+
};
|
|
1534
|
+
await navigate[a.args.direction ?? "back"]();
|
|
1535
|
+
return {};
|
|
1536
|
+
}
|
|
1537
|
+
};
|
|
1538
|
+
/** The live page (a new object after a reconnect), as pixel-level Playwright. */
|
|
1539
|
+
get page() {
|
|
1540
|
+
const page = this.browser.page;
|
|
1541
|
+
if (!isNativePage(page))
|
|
1542
|
+
throw new Error(
|
|
1543
|
+
"native computer use needs a Playwright page (mouse.move/click/down/up/wheel, context())"
|
|
1544
|
+
);
|
|
1545
|
+
return page;
|
|
1546
|
+
}
|
|
1547
|
+
run(action) {
|
|
1548
|
+
return this.handlers[action.name](action);
|
|
1549
|
+
}
|
|
1550
|
+
/** A PNG of the viewport at the model's display size. */
|
|
1551
|
+
async screenshot() {
|
|
1552
|
+
if (!this.display.scaled) return this.page.screenshot({ type: "png" });
|
|
1553
|
+
const { viewportWidth: width, viewportHeight: height } = this.display;
|
|
1554
|
+
return this.capture({ x: 0, y: 0, width, height }, this.display.scale);
|
|
1555
|
+
}
|
|
1556
|
+
/** Whether keystrokes go to a credential field (a password input, or one
|
|
1557
|
+
* named like a token, key or PIN), looking through shadow roots and
|
|
1558
|
+
* same-origin frames. An unreadable page, a cross-origin frame or a focus
|
|
1559
|
+
* that is not a text field (a closed shadow root's host) counts as one. */
|
|
1560
|
+
async focusedFieldIsSecret() {
|
|
1561
|
+
let described;
|
|
1562
|
+
try {
|
|
1563
|
+
described = String(await this.page.evaluate(FOCUSED_FIELD_JS) ?? "");
|
|
1564
|
+
} catch {
|
|
1565
|
+
return true;
|
|
1566
|
+
}
|
|
1567
|
+
return SECRET_FOCUS.some((prefix) => described.startsWith(prefix)) || SECRET_KEY.test(described);
|
|
1568
|
+
}
|
|
1569
|
+
/** CDP renders a clip at the page's device pixel ratio as well as its
|
|
1570
|
+
* `scale` (a Retina host doubles it), so a capture of the wrong width
|
|
1571
|
+
* measures that ratio and is taken once more, corrected. */
|
|
1572
|
+
async capture(clip, scale) {
|
|
1573
|
+
const wanted = Math.round(clip.width * scale);
|
|
1574
|
+
const png = await this.cdpCapture(clip, scale / this.pixelRatio);
|
|
1575
|
+
const width = pngWidth(png);
|
|
1576
|
+
if (width === null || Math.abs(width - wanted) <= 1) return png;
|
|
1577
|
+
this.pixelRatio *= width / wanted;
|
|
1578
|
+
return this.cdpCapture(clip, scale / this.pixelRatio);
|
|
1579
|
+
}
|
|
1580
|
+
async cdpCapture(clip, scale) {
|
|
1581
|
+
const page = this.page;
|
|
1582
|
+
const session = await page.context().newCDPSession(page);
|
|
1583
|
+
try {
|
|
1584
|
+
const shot = await session.send("Page.captureScreenshot", {
|
|
1585
|
+
format: "png",
|
|
1586
|
+
clip: { ...clip, scale }
|
|
1587
|
+
});
|
|
1588
|
+
return Buffer.from(shot.data, "base64");
|
|
1589
|
+
} finally {
|
|
1590
|
+
await session.detach();
|
|
1591
|
+
}
|
|
1592
|
+
}
|
|
1593
|
+
point(action) {
|
|
1594
|
+
const { x, y } = action.args;
|
|
1595
|
+
return x === void 0 || y === void 0 ? this.cursor : [x, y];
|
|
1596
|
+
}
|
|
1597
|
+
async moveTo(point2, steps = 1) {
|
|
1598
|
+
const [x, y] = this.display.toPage(point2[0], point2[1]);
|
|
1599
|
+
await this.page.mouse.move(x, y, { steps });
|
|
1600
|
+
this.cursor = point2;
|
|
1601
|
+
}
|
|
1602
|
+
async held(modifiers, fn) {
|
|
1603
|
+
for (const key2 of modifiers) await this.page.keyboard.down(key2);
|
|
1604
|
+
try {
|
|
1605
|
+
await fn();
|
|
1606
|
+
} finally {
|
|
1607
|
+
for (const key2 of [...modifiers].reverse())
|
|
1608
|
+
await this.page.keyboard.up(key2);
|
|
1609
|
+
}
|
|
1610
|
+
return {};
|
|
1611
|
+
}
|
|
1612
|
+
async zoom(action) {
|
|
1613
|
+
const [x0, y0, x1, y1] = action.args.region ?? [0, 0, 0, 0];
|
|
1614
|
+
const [left, top] = this.display.toPage(x0, y0);
|
|
1615
|
+
const [right, bottom] = this.display.toPage(x1, y1);
|
|
1616
|
+
if (right <= left || bottom <= top)
|
|
1617
|
+
throw new Error("zoom region must have x1 > x0 and y1 > y0");
|
|
1618
|
+
const width = right - left;
|
|
1619
|
+
const height = bottom - top;
|
|
1620
|
+
const scale = Math.min(
|
|
1621
|
+
this.display.width / width,
|
|
1622
|
+
this.display.height / height
|
|
1623
|
+
);
|
|
1624
|
+
return {
|
|
1625
|
+
image: await this.capture({ x: left, y: top, width, height }, scale)
|
|
1626
|
+
};
|
|
1627
|
+
}
|
|
1628
|
+
async click(action) {
|
|
1629
|
+
const point2 = this.point(action);
|
|
1630
|
+
return this.held(action.args.modifiers ?? [], async () => {
|
|
1631
|
+
await this.moveTo(point2);
|
|
1632
|
+
const [x, y] = this.display.toPage(point2[0], point2[1]);
|
|
1633
|
+
await this.page.mouse.click(x, y, {
|
|
1634
|
+
button: action.args.button ?? "left",
|
|
1635
|
+
clickCount: action.args.count ?? 1
|
|
1636
|
+
});
|
|
1637
|
+
});
|
|
1638
|
+
}
|
|
1639
|
+
async drag(action) {
|
|
1640
|
+
const path16 = action.args.path ?? [];
|
|
1641
|
+
if (path16.length < 2) throw new Error("a drag needs at least two points");
|
|
1642
|
+
return this.held(action.args.modifiers ?? [], async () => {
|
|
1643
|
+
await this.moveTo(path16[0]);
|
|
1644
|
+
await this.page.mouse.down({ button: "left" });
|
|
1645
|
+
try {
|
|
1646
|
+
for (const point2 of path16.slice(1)) await this.moveTo(point2, DRAG_STEPS);
|
|
1647
|
+
} finally {
|
|
1648
|
+
await this.page.mouse.up({ button: "left" });
|
|
1649
|
+
}
|
|
1650
|
+
});
|
|
1651
|
+
}
|
|
1652
|
+
async scroll(action) {
|
|
1653
|
+
await this.moveTo(this.point(action));
|
|
1654
|
+
const scale = this.display.scale;
|
|
1655
|
+
return this.held(
|
|
1656
|
+
action.args.modifiers ?? [],
|
|
1657
|
+
() => this.page.mouse.wheel(
|
|
1658
|
+
(action.args.dx ?? 0) / scale,
|
|
1659
|
+
(action.args.dy ?? 0) / scale
|
|
1660
|
+
)
|
|
1661
|
+
);
|
|
1662
|
+
}
|
|
1663
|
+
async key(action) {
|
|
1664
|
+
const combo = (action.args.keys ?? []).join("+");
|
|
1665
|
+
for (let i = 0; i < (action.args.repeat ?? 1); i += 1)
|
|
1666
|
+
await this.page.keyboard.press(combo);
|
|
1667
|
+
return {};
|
|
1668
|
+
}
|
|
1669
|
+
};
|
|
1670
|
+
}
|
|
1671
|
+
});
|
|
1672
|
+
|
|
1673
|
+
// src/tracing/media.ts
|
|
1674
|
+
async function putBytes(url, data, headers) {
|
|
1675
|
+
const controller = new AbortController();
|
|
1676
|
+
const timer = setTimeout(() => controller.abort(), PUT_TIMEOUT_MS);
|
|
1677
|
+
try {
|
|
1678
|
+
const res = await fetch(url, {
|
|
1679
|
+
method: "PUT",
|
|
1680
|
+
body: new Uint8Array(data),
|
|
1681
|
+
headers,
|
|
1682
|
+
signal: controller.signal
|
|
1683
|
+
});
|
|
1684
|
+
return {
|
|
1685
|
+
status: res.status,
|
|
1686
|
+
error: res.ok ? null : (await res.text()).slice(0, MAX_UPLOAD_ERROR)
|
|
1687
|
+
};
|
|
1688
|
+
} catch (error) {
|
|
1689
|
+
return {
|
|
1690
|
+
status: NETWORK_FAILURE_STATUS,
|
|
1691
|
+
error: error instanceof Error ? error.name : "Error"
|
|
1692
|
+
};
|
|
1693
|
+
} finally {
|
|
1694
|
+
clearTimeout(timer);
|
|
1695
|
+
}
|
|
1696
|
+
}
|
|
1697
|
+
var import_node_crypto, MEDIA_PATH, MAX_MEDIA_BYTES, PUT_TIMEOUT_MS, MAX_UPLOAD_ERROR, NETWORK_FAILURE_STATUS, MediaUploadError, MediaReference, MediaUploader;
|
|
1698
|
+
var init_media = __esm({
|
|
1699
|
+
"src/tracing/media.ts"() {
|
|
1700
|
+
"use strict";
|
|
1701
|
+
import_node_crypto = require("crypto");
|
|
1702
|
+
init_transport();
|
|
1703
|
+
MEDIA_PATH = "/api/public/media";
|
|
1704
|
+
MAX_MEDIA_BYTES = 5 * 1024 * 1024;
|
|
1705
|
+
PUT_TIMEOUT_MS = 3e4;
|
|
1706
|
+
MAX_UPLOAD_ERROR = 500;
|
|
1707
|
+
NETWORK_FAILURE_STATUS = 599;
|
|
1708
|
+
MediaUploadError = class extends Error {
|
|
1709
|
+
constructor(message, status) {
|
|
1710
|
+
super(message);
|
|
1711
|
+
this.status = status;
|
|
1712
|
+
this.name = "MediaUploadError";
|
|
1713
|
+
}
|
|
1714
|
+
status;
|
|
1715
|
+
};
|
|
1716
|
+
MediaReference = class {
|
|
1717
|
+
constructor(mediaId, contentType) {
|
|
1718
|
+
this.mediaId = mediaId;
|
|
1719
|
+
this.contentType = contentType;
|
|
1720
|
+
}
|
|
1721
|
+
mediaId;
|
|
1722
|
+
contentType;
|
|
1723
|
+
toString() {
|
|
1724
|
+
return `@@@langfuseMedia:type=${this.contentType}|id=${this.mediaId}|source=bytes@@@`;
|
|
1725
|
+
}
|
|
1726
|
+
};
|
|
1727
|
+
MediaUploader = class _MediaUploader {
|
|
1728
|
+
constructor(transport, put = putBytes, maxBytes = MAX_MEDIA_BYTES) {
|
|
1729
|
+
this.transport = transport;
|
|
1730
|
+
this.put = put;
|
|
1731
|
+
this.maxBytes = maxBytes;
|
|
1732
|
+
}
|
|
1733
|
+
transport;
|
|
1734
|
+
put;
|
|
1735
|
+
maxBytes;
|
|
1736
|
+
/** The uploader for `GATEWAY_HOST` / `GATEWAY_PUBLIC_KEY` /
|
|
1737
|
+
* `GATEWAY_SECRET_KEY` (the keys tracing exports with); null when any is unset. */
|
|
1738
|
+
static fromEnv(env = process.env) {
|
|
1739
|
+
const host = env.GATEWAY_HOST;
|
|
1740
|
+
const publicKey = env.GATEWAY_PUBLIC_KEY;
|
|
1741
|
+
const secretKey = env.GATEWAY_SECRET_KEY;
|
|
1742
|
+
if (!host || !publicKey || !secretKey) return null;
|
|
1743
|
+
return new _MediaUploader(
|
|
1744
|
+
new PlatformTransport({
|
|
1745
|
+
host: host.replace(/\/$/, ""),
|
|
1746
|
+
publicKey,
|
|
1747
|
+
secretKey
|
|
1748
|
+
})
|
|
1749
|
+
);
|
|
1750
|
+
}
|
|
1751
|
+
/** Store `data` linked to the trace (and observation) and return its reference. */
|
|
1752
|
+
async upload(data, link) {
|
|
1753
|
+
if (data.length > this.maxBytes)
|
|
1754
|
+
throw new MediaUploadError(
|
|
1755
|
+
`media is ${data.length} bytes, over the ${this.maxBytes}-byte cap`
|
|
1756
|
+
);
|
|
1757
|
+
const sha256Hash = (0, import_node_crypto.createHash)("sha256").update(data).digest("base64");
|
|
1758
|
+
const answer = await this.send("POST", MEDIA_PATH, {
|
|
1759
|
+
traceId: link.traceId,
|
|
1760
|
+
observationId: link.observationId,
|
|
1761
|
+
contentType: link.contentType,
|
|
1762
|
+
contentLength: data.length,
|
|
1763
|
+
sha256Hash,
|
|
1764
|
+
field: link.field
|
|
1765
|
+
});
|
|
1766
|
+
if (typeof answer.mediaId !== "string" || !answer.mediaId)
|
|
1767
|
+
throw new MediaUploadError(
|
|
1768
|
+
"POST /api/public/media answered without a mediaId"
|
|
1769
|
+
);
|
|
1770
|
+
const reference = new MediaReference(answer.mediaId, link.contentType);
|
|
1771
|
+
if (answer.uploadUrl)
|
|
1772
|
+
await this.store(reference, answer.uploadUrl, data, sha256Hash);
|
|
1773
|
+
return reference;
|
|
1774
|
+
}
|
|
1775
|
+
async store(reference, url, data, sha256Hash) {
|
|
1776
|
+
const started = Date.now();
|
|
1777
|
+
const { status, error } = await this.put(url, data, {
|
|
1778
|
+
"Content-Type": reference.contentType,
|
|
1779
|
+
"x-amz-checksum-sha256": sha256Hash,
|
|
1780
|
+
"x-ms-blob-type": "BlockBlob"
|
|
1781
|
+
});
|
|
1782
|
+
await this.send(
|
|
1783
|
+
"PATCH",
|
|
1784
|
+
`${MEDIA_PATH}/${encodeURIComponent(reference.mediaId)}`,
|
|
1785
|
+
{
|
|
1786
|
+
uploadedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1787
|
+
uploadHttpStatus: status,
|
|
1788
|
+
uploadHttpError: error,
|
|
1789
|
+
uploadTimeMs: Date.now() - started
|
|
1790
|
+
}
|
|
1791
|
+
);
|
|
1792
|
+
if (status < 200 || status >= 300)
|
|
1793
|
+
throw new MediaUploadError(
|
|
1794
|
+
`media storage refused the upload (HTTP ${status})`,
|
|
1795
|
+
status
|
|
1796
|
+
);
|
|
1797
|
+
}
|
|
1798
|
+
async send(method, route, body) {
|
|
1799
|
+
const reply = await this.transport.send(method, route, body);
|
|
1800
|
+
if (!reply.ok)
|
|
1801
|
+
throw new MediaUploadError(
|
|
1802
|
+
`${method} ${route} -> ${reply.status}`,
|
|
1803
|
+
reply.status
|
|
1804
|
+
);
|
|
1805
|
+
return reply.text ? JSON.parse(reply.text) : {};
|
|
1806
|
+
}
|
|
1807
|
+
};
|
|
1808
|
+
}
|
|
1809
|
+
});
|
|
1810
|
+
|
|
1811
|
+
// src/worlds/nativeComputer/trace.ts
|
|
1812
|
+
function loadOtelApi() {
|
|
1813
|
+
if (otelApi !== void 0) return otelApi;
|
|
1814
|
+
try {
|
|
1815
|
+
otelApi = require("@opentelemetry/api");
|
|
1816
|
+
} catch {
|
|
1817
|
+
otelApi = null;
|
|
1818
|
+
}
|
|
1819
|
+
return otelApi;
|
|
1820
|
+
}
|
|
1821
|
+
function errorText(error) {
|
|
1822
|
+
return error instanceof Error ? `${error.name}: ${error.message}` : String(error);
|
|
1823
|
+
}
|
|
1824
|
+
function errorName(error) {
|
|
1825
|
+
return error instanceof Error ? error.name : "Error";
|
|
1826
|
+
}
|
|
1827
|
+
var SPAN_PREFIX, MAX_UPLOAD_FAILURES, TRACER_NAME, MAX_ERROR, otelApi, ActionTracer;
|
|
1828
|
+
var init_trace = __esm({
|
|
1829
|
+
"src/worlds/nativeComputer/trace.ts"() {
|
|
1830
|
+
"use strict";
|
|
1831
|
+
init_media();
|
|
1832
|
+
SPAN_PREFIX = "computer.";
|
|
1833
|
+
MAX_UPLOAD_FAILURES = 3;
|
|
1834
|
+
TRACER_NAME = "@withgateway/sdk";
|
|
1835
|
+
MAX_ERROR = 1e3;
|
|
1836
|
+
ActionTracer = class _ActionTracer {
|
|
1837
|
+
constructor(media, warn3 = (m) => console.warn(m)) {
|
|
1838
|
+
this.media = media;
|
|
1839
|
+
this.warn = warn3;
|
|
1840
|
+
}
|
|
1841
|
+
media;
|
|
1842
|
+
warn;
|
|
1843
|
+
failures = 0;
|
|
1844
|
+
warned = false;
|
|
1845
|
+
static fromEnv() {
|
|
1846
|
+
return new _ActionTracer(MediaUploader.fromEnv());
|
|
1847
|
+
}
|
|
1848
|
+
/** `args` are already redacted. A failure's status goes through `scrub`:
|
|
1849
|
+
* browser errors quote the session's ws URL and UI token. */
|
|
1850
|
+
async span(action, args, run, capture, scrub) {
|
|
1851
|
+
const otel = loadOtelApi();
|
|
1852
|
+
if (!otel) return run();
|
|
1853
|
+
const { SpanStatusCode: SpanStatusCode3, trace: trace5 } = otel;
|
|
1854
|
+
const attributes = {
|
|
1855
|
+
"gateway.observation.type": "tool",
|
|
1856
|
+
"tool.name": SPAN_PREFIX + action.name,
|
|
1857
|
+
"gateway.observation.input": JSON.stringify({
|
|
1858
|
+
action: action.name,
|
|
1859
|
+
...args
|
|
1860
|
+
})
|
|
1861
|
+
};
|
|
1862
|
+
return trace5.getTracer(TRACER_NAME).startActiveSpan(
|
|
1863
|
+
SPAN_PREFIX + action.name,
|
|
1864
|
+
{ attributes },
|
|
1865
|
+
async (span) => {
|
|
1866
|
+
try {
|
|
1867
|
+
const result = await run();
|
|
1868
|
+
await this.finish(span, result, capture);
|
|
1869
|
+
span.setStatus({ code: SpanStatusCode3.OK });
|
|
1870
|
+
return result;
|
|
1871
|
+
} catch (error) {
|
|
1872
|
+
span.setStatus({
|
|
1873
|
+
code: SpanStatusCode3.ERROR,
|
|
1874
|
+
message: scrub(errorText(error)).slice(0, MAX_ERROR)
|
|
1875
|
+
});
|
|
1876
|
+
throw error;
|
|
1877
|
+
} finally {
|
|
1878
|
+
span.end();
|
|
1879
|
+
}
|
|
1880
|
+
}
|
|
1881
|
+
);
|
|
1882
|
+
}
|
|
1883
|
+
async finish(span, result, capture) {
|
|
1884
|
+
if (!span.isRecording()) return;
|
|
1885
|
+
const output = {
|
|
1886
|
+
screenshot: await this.screenshot(span, result, capture)
|
|
1887
|
+
};
|
|
1888
|
+
if (result.text !== void 0) output.text = result.text;
|
|
1889
|
+
span.setAttribute("gateway.observation.output", JSON.stringify(output));
|
|
1890
|
+
}
|
|
1891
|
+
async screenshot(span, result, capture) {
|
|
1892
|
+
let png;
|
|
1893
|
+
try {
|
|
1894
|
+
png = result.image ?? await capture();
|
|
1895
|
+
} catch (error) {
|
|
1896
|
+
return `[screenshot unavailable: ${errorName(error)}]`;
|
|
1897
|
+
}
|
|
1898
|
+
return this.reference(png, span);
|
|
1899
|
+
}
|
|
1900
|
+
async reference(png, span) {
|
|
1901
|
+
if (!this.media)
|
|
1902
|
+
return "[screenshot not uploaded: GATEWAY_HOST / GATEWAY_PUBLIC_KEY / GATEWAY_SECRET_KEY unset]";
|
|
1903
|
+
if (this.failures >= MAX_UPLOAD_FAILURES)
|
|
1904
|
+
return "[screenshot not uploaded: uploads disabled after repeated failures]";
|
|
1905
|
+
const { traceId, spanId } = span.spanContext();
|
|
1906
|
+
try {
|
|
1907
|
+
const reference = await this.media.upload(png, {
|
|
1908
|
+
contentType: "image/png",
|
|
1909
|
+
traceId,
|
|
1910
|
+
observationId: spanId,
|
|
1911
|
+
field: "output"
|
|
1912
|
+
});
|
|
1913
|
+
this.failures = 0;
|
|
1914
|
+
return reference.toString();
|
|
1915
|
+
} catch (error) {
|
|
1916
|
+
return this.failed(error);
|
|
1917
|
+
}
|
|
1918
|
+
}
|
|
1919
|
+
failed(error) {
|
|
1920
|
+
this.failures += 1;
|
|
1921
|
+
if (!this.warned) {
|
|
1922
|
+
this.warned = true;
|
|
1923
|
+
this.warn(
|
|
1924
|
+
`native computer: screenshot upload failed (${errorName(error)}: ${error instanceof Error ? error.message : String(error)}); spans keep going without it`
|
|
1925
|
+
);
|
|
1926
|
+
}
|
|
1927
|
+
return `[screenshot not uploaded: ${errorName(error)}]`;
|
|
1928
|
+
}
|
|
1929
|
+
};
|
|
1930
|
+
}
|
|
1931
|
+
});
|
|
1932
|
+
|
|
1933
|
+
// src/worlds/nativeComputer/base.ts
|
|
1934
|
+
function readField(item, ...names) {
|
|
1935
|
+
const record = item ?? {};
|
|
1936
|
+
return names.map((name) => record[name]).find((value) => value !== void 0 && value !== null);
|
|
1937
|
+
}
|
|
1938
|
+
var REPLAYABLE, SETTLING, EVENT_PREFIX, NativeComputer;
|
|
1939
|
+
var init_base = __esm({
|
|
1940
|
+
"src/worlds/nativeComputer/base.ts"() {
|
|
1941
|
+
"use strict";
|
|
1942
|
+
init_browser();
|
|
1943
|
+
init_actions();
|
|
1944
|
+
init_display();
|
|
1945
|
+
init_screen();
|
|
1946
|
+
init_trace();
|
|
1947
|
+
REPLAYABLE = /* @__PURE__ */ new Set(["screenshot", "zoom", "cursor_position", "wait"]);
|
|
1948
|
+
SETTLING = /* @__PURE__ */ new Set(["click", "mouse_up", "drag", "key", "history"]);
|
|
1949
|
+
EVENT_PREFIX = "computer_";
|
|
1950
|
+
NativeComputer = class _NativeComputer {
|
|
1951
|
+
constructor(browser, options = {}) {
|
|
1952
|
+
this.browser = browser;
|
|
1953
|
+
const kind = this.constructor;
|
|
1954
|
+
this.display = Display.forViewport(
|
|
1955
|
+
browser.viewport,
|
|
1956
|
+
options.display,
|
|
1957
|
+
(w, h) => kind.fits(w, h)
|
|
1958
|
+
);
|
|
1959
|
+
this.screen = new Screen(browser, this.display);
|
|
1960
|
+
this.tracer = options.tracer ?? ActionTracer.fromEnv();
|
|
1961
|
+
}
|
|
1962
|
+
browser;
|
|
1963
|
+
static kinds = /* @__PURE__ */ new Map();
|
|
1964
|
+
display;
|
|
1965
|
+
screen;
|
|
1966
|
+
tracer;
|
|
1967
|
+
queue = Promise.resolve();
|
|
1968
|
+
static register(provider, kind) {
|
|
1969
|
+
_NativeComputer.kinds.set(provider, kind);
|
|
1970
|
+
}
|
|
1971
|
+
static get providers() {
|
|
1972
|
+
return [..._NativeComputer.kinds.keys()].sort();
|
|
1973
|
+
}
|
|
1974
|
+
static forProvider(provider, browser, options = {}) {
|
|
1975
|
+
const Kind = _NativeComputer.kinds.get(provider);
|
|
1976
|
+
if (!Kind)
|
|
1977
|
+
throw new Error(
|
|
1978
|
+
`unknown computer-use provider '${provider}'; choose from ${_NativeComputer.providers.join(", ")}`
|
|
1979
|
+
);
|
|
1980
|
+
return new Kind(browser, options);
|
|
1981
|
+
}
|
|
1982
|
+
/** Whether a screenshot of this size is within the provider's limits. */
|
|
1983
|
+
static fits(_width, _height) {
|
|
1984
|
+
return true;
|
|
1985
|
+
}
|
|
1986
|
+
/** Run one provider-shaped action (an OpenAI action object, or an Anthropic
|
|
1987
|
+
* `{ action: "left_click", ... }` input) and return what it produced: the
|
|
1988
|
+
* door for any agent framework that hands actions over one at a time. */
|
|
1989
|
+
executeAction(raw) {
|
|
1990
|
+
return this.perform(this.parse(raw));
|
|
1991
|
+
}
|
|
1992
|
+
/** Run one action on the page: reported on the session's browser timeline
|
|
1993
|
+
* and, when tracing is on, as a span with the screen after. */
|
|
1994
|
+
async perform(action) {
|
|
1995
|
+
const secret = action.name === "type" && await this.screen.focusedFieldIsSecret();
|
|
1996
|
+
const event = EVENT_PREFIX + action.name;
|
|
1997
|
+
const args = redactActionArgs(event, action.recordArgs(secret));
|
|
1998
|
+
return this.tracer.span(
|
|
1999
|
+
action,
|
|
2000
|
+
args,
|
|
2001
|
+
() => this.browser.act(
|
|
2002
|
+
event,
|
|
2003
|
+
args,
|
|
2004
|
+
() => this.runOnScreen(action),
|
|
2005
|
+
this.onLoss(action)
|
|
2006
|
+
),
|
|
2007
|
+
() => this.screen.screenshot(),
|
|
2008
|
+
(text2) => this.browser.scrub(text2)
|
|
2009
|
+
);
|
|
2010
|
+
}
|
|
2011
|
+
async performAll(actions) {
|
|
2012
|
+
const results = [];
|
|
2013
|
+
for (const action of actions) results.push(await this.perform(action));
|
|
2014
|
+
return results;
|
|
2015
|
+
}
|
|
2016
|
+
/** The screen as the model sees it, as a traced `screenshot` action. */
|
|
2017
|
+
async screenshot() {
|
|
2018
|
+
return (await this.perform(new ComputerAction("screenshot"))).image ?? Buffer.alloc(0);
|
|
2019
|
+
}
|
|
2020
|
+
/** Run `fn` after every earlier call made through here: the AI SDK starts a
|
|
2021
|
+
* step's tool calls concurrently, but one screen takes one action at a time. */
|
|
2022
|
+
serial(fn) {
|
|
2023
|
+
const next = this.queue.then(fn, fn);
|
|
2024
|
+
this.queue = next.catch(() => void 0);
|
|
2025
|
+
return next;
|
|
2026
|
+
}
|
|
2027
|
+
async runOnScreen(action) {
|
|
2028
|
+
const result = await this.screen.run(action);
|
|
2029
|
+
if (SETTLING.has(action.name)) await this.browser.settle();
|
|
2030
|
+
return result;
|
|
2031
|
+
}
|
|
2032
|
+
onLoss(action) {
|
|
2033
|
+
return REPLAYABLE.has(action.name) ? "retry" : "report";
|
|
2034
|
+
}
|
|
2035
|
+
};
|
|
2036
|
+
}
|
|
2037
|
+
});
|
|
2038
|
+
|
|
2039
|
+
// src/worlds/nativeComputer/keys.ts
|
|
2040
|
+
function playwrightKey(token) {
|
|
2041
|
+
return KEY_NAMES[token.toLowerCase()] ?? token;
|
|
2042
|
+
}
|
|
2043
|
+
function letterOrName(key2) {
|
|
2044
|
+
return /^[a-zA-Z]$/.test(key2) ? key2.toLowerCase() : playwrightKey(key2);
|
|
2045
|
+
}
|
|
2046
|
+
function modifierChord(text2) {
|
|
2047
|
+
return typeof text2 === "string" && text2 ? [...KeyChord.fromXdotool(text2).keys] : [];
|
|
2048
|
+
}
|
|
2049
|
+
function modifierKeys(keys) {
|
|
2050
|
+
return Array.isArray(keys) && keys.length > 0 ? [...KeyChord.fromKeys(keys.map(String)).keys] : [];
|
|
2051
|
+
}
|
|
2052
|
+
var F_KEYS, KEY_NAMES, KeyChord;
|
|
2053
|
+
var init_keys = __esm({
|
|
2054
|
+
"src/worlds/nativeComputer/keys.ts"() {
|
|
2055
|
+
"use strict";
|
|
2056
|
+
F_KEYS = Object.fromEntries(
|
|
2057
|
+
Array.from({ length: 12 }, (_, i) => [`f${i + 1}`, `F${i + 1}`])
|
|
2058
|
+
);
|
|
2059
|
+
KEY_NAMES = {
|
|
2060
|
+
return: "Enter",
|
|
2061
|
+
enter: "Enter",
|
|
2062
|
+
kp_enter: "Enter",
|
|
2063
|
+
esc: "Escape",
|
|
2064
|
+
escape: "Escape",
|
|
2065
|
+
tab: "Tab",
|
|
2066
|
+
space: "Space",
|
|
2067
|
+
backspace: "Backspace",
|
|
2068
|
+
delete: "Delete",
|
|
2069
|
+
del: "Delete",
|
|
2070
|
+
insert: "Insert",
|
|
2071
|
+
home: "Home",
|
|
2072
|
+
end: "End",
|
|
2073
|
+
pageup: "PageUp",
|
|
2074
|
+
page_up: "PageUp",
|
|
2075
|
+
prior: "PageUp",
|
|
2076
|
+
pagedown: "PageDown",
|
|
2077
|
+
page_down: "PageDown",
|
|
2078
|
+
next: "PageDown",
|
|
2079
|
+
up: "ArrowUp",
|
|
2080
|
+
arrowup: "ArrowUp",
|
|
2081
|
+
down: "ArrowDown",
|
|
2082
|
+
arrowdown: "ArrowDown",
|
|
2083
|
+
left: "ArrowLeft",
|
|
2084
|
+
arrowleft: "ArrowLeft",
|
|
2085
|
+
right: "ArrowRight",
|
|
2086
|
+
arrowright: "ArrowRight",
|
|
2087
|
+
ctrl: "Control",
|
|
2088
|
+
control: "Control",
|
|
2089
|
+
shift: "Shift",
|
|
2090
|
+
alt: "Alt",
|
|
2091
|
+
option: "Alt",
|
|
2092
|
+
super: "Meta",
|
|
2093
|
+
meta: "Meta",
|
|
2094
|
+
cmd: "Meta",
|
|
2095
|
+
command: "Meta",
|
|
2096
|
+
win: "Meta",
|
|
2097
|
+
capslock: "CapsLock",
|
|
2098
|
+
caps_lock: "CapsLock",
|
|
2099
|
+
plus: "+",
|
|
2100
|
+
minus: "-",
|
|
2101
|
+
...F_KEYS
|
|
2102
|
+
};
|
|
2103
|
+
KeyChord = class _KeyChord {
|
|
2104
|
+
constructor(keys) {
|
|
2105
|
+
this.keys = keys;
|
|
2106
|
+
if (keys.length === 0)
|
|
2107
|
+
throw new Error("a key action needs at least one key");
|
|
2108
|
+
}
|
|
2109
|
+
keys;
|
|
2110
|
+
/** `ctrl+shift+t` / `Return`: Anthropic's vocabulary, case kept. */
|
|
2111
|
+
static fromXdotool(text2) {
|
|
2112
|
+
return new _KeyChord(
|
|
2113
|
+
text2.trim().split("+").filter(Boolean).map(playwrightKey)
|
|
2114
|
+
);
|
|
2115
|
+
}
|
|
2116
|
+
/** `["CTRL", "A"]`: OpenAI's vocabulary. A lone letter is the unshifted key. */
|
|
2117
|
+
static fromKeys(keys) {
|
|
2118
|
+
return new _KeyChord(keys.map(letterOrName));
|
|
2119
|
+
}
|
|
2120
|
+
/** What `page.keyboard.press` takes: `Control+a`. */
|
|
2121
|
+
get combo() {
|
|
2122
|
+
return this.keys.join("+");
|
|
2123
|
+
}
|
|
2124
|
+
};
|
|
2125
|
+
}
|
|
2126
|
+
});
|
|
2127
|
+
|
|
2128
|
+
// src/worlds/nativeComputer/anthropic.ts
|
|
2129
|
+
function required(raw, key2) {
|
|
2130
|
+
const value = raw[key2];
|
|
2131
|
+
if (value === void 0 || value === null)
|
|
2132
|
+
throw new Error(`${String(raw.action)} needs ${key2}`);
|
|
2133
|
+
return value;
|
|
2134
|
+
}
|
|
2135
|
+
function pair(raw, key2) {
|
|
2136
|
+
const value = required(raw, key2);
|
|
2137
|
+
return [toInt(value[0]), toInt(value[1])];
|
|
2138
|
+
}
|
|
2139
|
+
function point(raw) {
|
|
2140
|
+
if (raw.coordinate === void 0 || raw.coordinate === null) return {};
|
|
2141
|
+
const [x, y] = pair(raw, "coordinate");
|
|
2142
|
+
return { x, y };
|
|
2143
|
+
}
|
|
2144
|
+
function chord(raw) {
|
|
2145
|
+
return [...KeyChord.fromXdotool(String(required(raw, "text"))).keys];
|
|
2146
|
+
}
|
|
2147
|
+
function click(button, count) {
|
|
2148
|
+
return (raw) => new ComputerAction("click", {
|
|
2149
|
+
...point(raw),
|
|
2150
|
+
button,
|
|
2151
|
+
count,
|
|
2152
|
+
modifiers: modifierChord(raw.text)
|
|
2153
|
+
});
|
|
2154
|
+
}
|
|
2155
|
+
var SCROLL_STEP_PX, NOT_EXECUTED, MAX_ERROR2, SCROLL_DIRECTIONS, MEMBERS, AnthropicComputer, AnthropicComputer20251124;
|
|
2156
|
+
var init_anthropic = __esm({
|
|
2157
|
+
"src/worlds/nativeComputer/anthropic.ts"() {
|
|
2158
|
+
"use strict";
|
|
2159
|
+
init_actions();
|
|
2160
|
+
init_base();
|
|
2161
|
+
init_keys();
|
|
2162
|
+
SCROLL_STEP_PX = 100;
|
|
2163
|
+
NOT_EXECUTED = "Not executed: an earlier computer action in this turn failed.";
|
|
2164
|
+
MAX_ERROR2 = 1e3;
|
|
2165
|
+
SCROLL_DIRECTIONS = {
|
|
2166
|
+
up: [0, -1],
|
|
2167
|
+
down: [0, 1],
|
|
2168
|
+
left: [-1, 0],
|
|
2169
|
+
right: [1, 0]
|
|
2170
|
+
};
|
|
2171
|
+
MEMBERS = {
|
|
2172
|
+
screenshot: () => new ComputerAction("screenshot"),
|
|
2173
|
+
zoom: (raw) => new ComputerAction("zoom", {
|
|
2174
|
+
region: required(raw, "region").map(toInt)
|
|
2175
|
+
}),
|
|
2176
|
+
left_click: click("left", 1),
|
|
2177
|
+
right_click: click("right", 1),
|
|
2178
|
+
middle_click: click("middle", 1),
|
|
2179
|
+
double_click: click("left", 2),
|
|
2180
|
+
triple_click: click("left", 3),
|
|
2181
|
+
left_click_drag: (raw) => new ComputerAction("drag", {
|
|
2182
|
+
path: [pair(raw, "start_coordinate"), pair(raw, "coordinate")],
|
|
2183
|
+
modifiers: modifierChord(raw.text)
|
|
2184
|
+
}),
|
|
2185
|
+
mouse_move: (raw) => {
|
|
2186
|
+
const [x, y] = pair(raw, "coordinate");
|
|
2187
|
+
return new ComputerAction("move", { x, y });
|
|
2188
|
+
},
|
|
2189
|
+
left_mouse_down: () => new ComputerAction("mouse_down", { button: "left" }),
|
|
2190
|
+
left_mouse_up: () => new ComputerAction("mouse_up", { button: "left" }),
|
|
2191
|
+
cursor_position: () => new ComputerAction("cursor_position"),
|
|
2192
|
+
scroll: (raw) => {
|
|
2193
|
+
const direction = String(raw.scroll_direction ?? "down");
|
|
2194
|
+
if (!Object.hasOwn(SCROLL_DIRECTIONS, direction))
|
|
2195
|
+
throw new Error(
|
|
2196
|
+
`scroll_direction must be one of ${Object.keys(SCROLL_DIRECTIONS).join(", ")}`
|
|
2197
|
+
);
|
|
2198
|
+
const [dx, dy] = SCROLL_DIRECTIONS[direction];
|
|
2199
|
+
const amount = toInt(raw.scroll_amount ?? 1) * SCROLL_STEP_PX;
|
|
2200
|
+
return new ComputerAction("scroll", {
|
|
2201
|
+
...point(raw),
|
|
2202
|
+
dx: dx * amount,
|
|
2203
|
+
dy: dy * amount,
|
|
2204
|
+
modifiers: modifierChord(raw.text)
|
|
2205
|
+
});
|
|
2206
|
+
},
|
|
2207
|
+
type: (raw) => new ComputerAction("type", { text: String(required(raw, "text")) }),
|
|
2208
|
+
key: (raw) => new ComputerAction("key", {
|
|
2209
|
+
keys: chord(raw),
|
|
2210
|
+
repeat: toInt(raw.repeat ?? 1)
|
|
2211
|
+
}),
|
|
2212
|
+
hold_key: (raw) => new ComputerAction("hold_key", {
|
|
2213
|
+
keys: chord(raw),
|
|
2214
|
+
seconds: toNumber(required(raw, "duration"))
|
|
2215
|
+
}),
|
|
2216
|
+
wait: (raw) => new ComputerAction("wait", { seconds: toNumber(raw.duration ?? 1) })
|
|
2217
|
+
};
|
|
2218
|
+
AnthropicComputer = class _AnthropicComputer extends NativeComputer {
|
|
2219
|
+
static TOOL_TYPE = "computer_toolset_20260801";
|
|
2220
|
+
static TOOLSET = "computer";
|
|
2221
|
+
static BETA = null;
|
|
2222
|
+
static MAX_LONG_EDGE = 2576;
|
|
2223
|
+
static MAX_VISUAL_TOKENS = 4784;
|
|
2224
|
+
static PATCH_PX = 28;
|
|
2225
|
+
static fits(width, height) {
|
|
2226
|
+
const tokens = Math.ceil(width / this.PATCH_PX) * Math.ceil(height / this.PATCH_PX);
|
|
2227
|
+
return Math.max(width, height) <= this.MAX_LONG_EDGE && tokens <= this.MAX_VISUAL_TOKENS;
|
|
2228
|
+
}
|
|
2229
|
+
tool() {
|
|
2230
|
+
return { type: _AnthropicComputer.TOOL_TYPE };
|
|
2231
|
+
}
|
|
2232
|
+
/** Whether a content block is a call to this computer. */
|
|
2233
|
+
owns(block) {
|
|
2234
|
+
return readField(block, "type") === "tool_use" && readField(block, "toolset_name") === _AnthropicComputer.TOOLSET;
|
|
2235
|
+
}
|
|
2236
|
+
member(block) {
|
|
2237
|
+
return [
|
|
2238
|
+
String(readField(block, "name")),
|
|
2239
|
+
{ ...readField(block, "input") ?? {} }
|
|
2240
|
+
];
|
|
2241
|
+
}
|
|
2242
|
+
parse(raw) {
|
|
2243
|
+
const name = String(readField(raw, "action"));
|
|
2244
|
+
const parser = Object.hasOwn(MEMBERS, name) ? MEMBERS[name] : void 0;
|
|
2245
|
+
if (!parser) throw new Error(`unknown computer action: ${name}`);
|
|
2246
|
+
return parser(raw);
|
|
2247
|
+
}
|
|
2248
|
+
/** Run every computer `tool_use` in a response's content, in order, and
|
|
2249
|
+
* return one `tool_result` per block. Other blocks are skipped. */
|
|
2250
|
+
async execute(content) {
|
|
2251
|
+
const results = [];
|
|
2252
|
+
let failed = false;
|
|
2253
|
+
for (const block of content) {
|
|
2254
|
+
if (!this.owns(block)) continue;
|
|
2255
|
+
if (failed) {
|
|
2256
|
+
results.push(this.envelope(block, NOT_EXECUTED, true));
|
|
2257
|
+
continue;
|
|
2258
|
+
}
|
|
2259
|
+
const [result, blockFailed] = await this.runBlock(block);
|
|
2260
|
+
results.push(result);
|
|
2261
|
+
failed = blockFailed;
|
|
2262
|
+
}
|
|
2263
|
+
return results;
|
|
2264
|
+
}
|
|
2265
|
+
/** The content an `ActionResult` goes back to the model as. */
|
|
2266
|
+
static content(result) {
|
|
2267
|
+
if (result.image)
|
|
2268
|
+
return [
|
|
2269
|
+
{
|
|
2270
|
+
type: "image",
|
|
2271
|
+
source: {
|
|
2272
|
+
type: "base64",
|
|
2273
|
+
media_type: "image/png",
|
|
2274
|
+
data: result.image.toString("base64")
|
|
2275
|
+
}
|
|
2276
|
+
}
|
|
2277
|
+
];
|
|
2278
|
+
return [{ type: "text", text: result.text ?? "OK" }];
|
|
2279
|
+
}
|
|
2280
|
+
/** For `anthropic.tools.computerToolset_20260801({ ...computer.aiSdk() })`
|
|
2281
|
+
* (or `computer_20251124` with the legacy kind): `execute` runs one action
|
|
2282
|
+
* and returns `{ type: "image", data }` or text; `toModelOutput` turns that
|
|
2283
|
+
* into the tool result. Calls run one at a time, and once a call fails the
|
|
2284
|
+
* rest of that step's calls answer as not executed. */
|
|
2285
|
+
aiSdk() {
|
|
2286
|
+
let failedStep;
|
|
2287
|
+
const execute = (input, options) => this.serial(async () => {
|
|
2288
|
+
const step = options?.messages?.length;
|
|
2289
|
+
if (step !== void 0 && step === failedStep)
|
|
2290
|
+
throw new Error(NOT_EXECUTED);
|
|
2291
|
+
try {
|
|
2292
|
+
return _AnthropicComputer.aiSdkOutput(await this.executeAction(input));
|
|
2293
|
+
} catch (error) {
|
|
2294
|
+
failedStep = step;
|
|
2295
|
+
throw error instanceof Error ? new Error(this.browser.scrub(error.message)) : error;
|
|
2296
|
+
}
|
|
2297
|
+
});
|
|
2298
|
+
return {
|
|
2299
|
+
execute,
|
|
2300
|
+
toModelOutput: ({ output }) => _AnthropicComputer.aiSdkModelOutput(output)
|
|
2301
|
+
};
|
|
2302
|
+
}
|
|
2303
|
+
static aiSdkOutput(result) {
|
|
2304
|
+
if (result.image)
|
|
2305
|
+
return { type: "image", data: result.image.toString("base64") };
|
|
2306
|
+
return result.text ?? "OK";
|
|
2307
|
+
}
|
|
2308
|
+
/** `image-data` is what AI SDK 6's Anthropic provider turns into an image
|
|
2309
|
+
* block; AI SDK 7 still accepts it (and converts it to a `file` part). */
|
|
2310
|
+
static aiSdkModelOutput(output) {
|
|
2311
|
+
if (typeof output === "string") return { type: "text", value: output };
|
|
2312
|
+
return {
|
|
2313
|
+
type: "content",
|
|
2314
|
+
value: [
|
|
2315
|
+
{ type: "image-data", data: output.data, mediaType: "image/png" }
|
|
2316
|
+
]
|
|
2317
|
+
};
|
|
2318
|
+
}
|
|
2319
|
+
envelope(block, content, isError = false) {
|
|
2320
|
+
return {
|
|
2321
|
+
type: "tool_result",
|
|
2322
|
+
tool_use_id: String(readField(block, "id")),
|
|
2323
|
+
toolset_name: _AnthropicComputer.TOOLSET,
|
|
2324
|
+
content,
|
|
2325
|
+
...isError ? { is_error: true } : {}
|
|
2326
|
+
};
|
|
2327
|
+
}
|
|
2328
|
+
async runBlock(block) {
|
|
2329
|
+
const [name, payload] = this.member(block);
|
|
2330
|
+
try {
|
|
2331
|
+
const result = await this.executeAction({ ...payload, action: name });
|
|
2332
|
+
return [this.envelope(block, _AnthropicComputer.content(result)), false];
|
|
2333
|
+
} catch (error) {
|
|
2334
|
+
const detail = error instanceof Error ? `${error.name}: ${error.message}` : String(error);
|
|
2335
|
+
return [
|
|
2336
|
+
this.envelope(
|
|
2337
|
+
block,
|
|
2338
|
+
this.browser.scrub(`Error: ${detail}`).slice(0, MAX_ERROR2),
|
|
2339
|
+
true
|
|
2340
|
+
),
|
|
2341
|
+
true
|
|
2342
|
+
];
|
|
2343
|
+
}
|
|
2344
|
+
}
|
|
2345
|
+
};
|
|
2346
|
+
AnthropicComputer20251124 = class _AnthropicComputer20251124 extends AnthropicComputer {
|
|
2347
|
+
static TOOL_TYPE = "computer_20251124";
|
|
2348
|
+
static BETA = "computer-use-2025-11-24";
|
|
2349
|
+
static MAX_LONG_EDGE = 1568;
|
|
2350
|
+
static MAX_PIXELS = 115e4;
|
|
2351
|
+
static fits(width, height) {
|
|
2352
|
+
return Math.max(width, height) <= this.MAX_LONG_EDGE && width * height <= this.MAX_PIXELS;
|
|
2353
|
+
}
|
|
2354
|
+
tool() {
|
|
2355
|
+
return {
|
|
2356
|
+
type: _AnthropicComputer20251124.TOOL_TYPE,
|
|
2357
|
+
name: AnthropicComputer.TOOLSET,
|
|
2358
|
+
display_width_px: this.display.width,
|
|
2359
|
+
display_height_px: this.display.height,
|
|
2360
|
+
enable_zoom: true
|
|
2361
|
+
};
|
|
2362
|
+
}
|
|
2363
|
+
owns(block) {
|
|
2364
|
+
return readField(block, "type") === "tool_use" && readField(block, "name") === AnthropicComputer.TOOLSET;
|
|
2365
|
+
}
|
|
2366
|
+
member(block) {
|
|
2367
|
+
const { action, ...payload } = readField(block, "input") ?? {};
|
|
2368
|
+
return [String(action ?? ""), payload];
|
|
2369
|
+
}
|
|
2370
|
+
envelope(block, content, isError = false) {
|
|
2371
|
+
const { toolset_name: _dropped, ...rest } = super.envelope(
|
|
2372
|
+
block,
|
|
2373
|
+
content,
|
|
2374
|
+
isError
|
|
2375
|
+
);
|
|
2376
|
+
return rest;
|
|
2377
|
+
}
|
|
2378
|
+
};
|
|
2379
|
+
NativeComputer.register("anthropic", AnthropicComputer);
|
|
2380
|
+
NativeComputer.register(
|
|
2381
|
+
"anthropic-computer-20251124",
|
|
2382
|
+
AnthropicComputer20251124
|
|
2383
|
+
);
|
|
2384
|
+
}
|
|
2385
|
+
});
|
|
2386
|
+
|
|
2387
|
+
// src/worlds/nativeComputer/openai.ts
|
|
2388
|
+
function safetyCheck(raw) {
|
|
2389
|
+
const check = { id: String(readField(raw, "id") ?? "") };
|
|
2390
|
+
const code = readField(raw, "code");
|
|
2391
|
+
const message = readField(raw, "message");
|
|
2392
|
+
if (code !== void 0) check.code = String(code);
|
|
2393
|
+
if (message !== void 0) check.message = String(message);
|
|
2394
|
+
return check;
|
|
2395
|
+
}
|
|
2396
|
+
function dataUrl(png) {
|
|
2397
|
+
return `data:image/png;base64,${png.toString("base64")}`;
|
|
2398
|
+
}
|
|
2399
|
+
function xy(raw) {
|
|
2400
|
+
return {
|
|
2401
|
+
x: toInt(readField(raw, "x") ?? 0),
|
|
2402
|
+
y: toInt(readField(raw, "y") ?? 0)
|
|
2403
|
+
};
|
|
2404
|
+
}
|
|
2405
|
+
function held(raw) {
|
|
2406
|
+
return modifierKeys(readField(raw, "keys"));
|
|
2407
|
+
}
|
|
2408
|
+
var WAIT_SECONDS, BUTTONS, HISTORY_BUTTONS, PendingSafetyChecks, ACTIONS, OpenAIComputer, OpenAIPreviewComputer;
|
|
2409
|
+
var init_openai = __esm({
|
|
2410
|
+
"src/worlds/nativeComputer/openai.ts"() {
|
|
2411
|
+
"use strict";
|
|
2412
|
+
init_actions();
|
|
2413
|
+
init_base();
|
|
2414
|
+
init_keys();
|
|
2415
|
+
WAIT_SECONDS = 1;
|
|
2416
|
+
BUTTONS = {
|
|
2417
|
+
left: "left",
|
|
2418
|
+
right: "right",
|
|
2419
|
+
wheel: "middle",
|
|
2420
|
+
middle: "middle"
|
|
2421
|
+
};
|
|
2422
|
+
HISTORY_BUTTONS = /* @__PURE__ */ new Set(["back", "forward"]);
|
|
2423
|
+
PendingSafetyChecks = class extends Error {
|
|
2424
|
+
constructor(callId, checks) {
|
|
2425
|
+
const listed = checks.map((c) => `${c.code ?? "check"}: ${c.message ?? ""}`.trim()).join("; ");
|
|
2426
|
+
super(
|
|
2427
|
+
`computer_call ${callId} needs ${checks.length} safety check(s) acknowledged: ${listed}`
|
|
2428
|
+
);
|
|
2429
|
+
this.callId = callId;
|
|
2430
|
+
this.checks = checks;
|
|
2431
|
+
this.name = "PendingSafetyChecks";
|
|
2432
|
+
}
|
|
2433
|
+
callId;
|
|
2434
|
+
checks;
|
|
2435
|
+
};
|
|
2436
|
+
ACTIONS = {
|
|
2437
|
+
click: (raw) => {
|
|
2438
|
+
const button = String(readField(raw, "button") ?? "left");
|
|
2439
|
+
if (HISTORY_BUTTONS.has(button))
|
|
2440
|
+
return new ComputerAction("history", {
|
|
2441
|
+
direction: button
|
|
2442
|
+
});
|
|
2443
|
+
if (!Object.hasOwn(BUTTONS, button))
|
|
2444
|
+
throw new Error(`unknown mouse button: ${button}`);
|
|
2445
|
+
return new ComputerAction("click", {
|
|
2446
|
+
...xy(raw),
|
|
2447
|
+
button: BUTTONS[button],
|
|
2448
|
+
count: 1,
|
|
2449
|
+
modifiers: held(raw)
|
|
2450
|
+
});
|
|
2451
|
+
},
|
|
2452
|
+
double_click: (raw) => new ComputerAction("click", {
|
|
2453
|
+
...xy(raw),
|
|
2454
|
+
button: "left",
|
|
2455
|
+
count: 2,
|
|
2456
|
+
modifiers: held(raw)
|
|
2457
|
+
}),
|
|
2458
|
+
drag: (raw) => new ComputerAction("drag", {
|
|
2459
|
+
path: (readField(raw, "path") ?? []).map(
|
|
2460
|
+
(p) => [toInt(readField(p, "x")), toInt(readField(p, "y"))]
|
|
2461
|
+
),
|
|
2462
|
+
modifiers: held(raw)
|
|
2463
|
+
}),
|
|
2464
|
+
keypress: (raw) => new ComputerAction("key", {
|
|
2465
|
+
keys: [
|
|
2466
|
+
...KeyChord.fromKeys(readField(raw, "keys") ?? []).keys
|
|
2467
|
+
],
|
|
2468
|
+
repeat: 1
|
|
2469
|
+
}),
|
|
2470
|
+
move: (raw) => new ComputerAction("move", { ...xy(raw), modifiers: held(raw) }),
|
|
2471
|
+
scroll: (raw) => new ComputerAction("scroll", {
|
|
2472
|
+
...xy(raw),
|
|
2473
|
+
dx: toInt(readField(raw, "scroll_x", "scrollX") ?? 0),
|
|
2474
|
+
dy: toInt(readField(raw, "scroll_y", "scrollY") ?? 0),
|
|
2475
|
+
modifiers: held(raw)
|
|
2476
|
+
}),
|
|
2477
|
+
type: (raw) => new ComputerAction("type", { text: String(readField(raw, "text") ?? "") }),
|
|
2478
|
+
wait: () => new ComputerAction("wait", { seconds: WAIT_SECONDS }),
|
|
2479
|
+
screenshot: () => new ComputerAction("screenshot")
|
|
2480
|
+
};
|
|
2481
|
+
OpenAIComputer = class _OpenAIComputer extends NativeComputer {
|
|
2482
|
+
tool() {
|
|
2483
|
+
return { type: "computer" };
|
|
2484
|
+
}
|
|
2485
|
+
owns(item) {
|
|
2486
|
+
return readField(item, "type") === "computer_call";
|
|
2487
|
+
}
|
|
2488
|
+
parse(raw) {
|
|
2489
|
+
const kind = String(readField(raw, "type"));
|
|
2490
|
+
const parser = Object.hasOwn(ACTIONS, kind) ? ACTIONS[kind] : void 0;
|
|
2491
|
+
if (!parser) throw new Error(`unknown computer action: ${kind}`);
|
|
2492
|
+
return parser(raw);
|
|
2493
|
+
}
|
|
2494
|
+
static actionsOf(call) {
|
|
2495
|
+
const batch = readField(call, "actions");
|
|
2496
|
+
if (Array.isArray(batch)) return batch;
|
|
2497
|
+
const single = readField(call, "action");
|
|
2498
|
+
return single === void 0 ? [] : [single];
|
|
2499
|
+
}
|
|
2500
|
+
/** Run a `computer_call`'s actions and return its `computer_call_output`.
|
|
2501
|
+
* Throws `PendingSafetyChecks` (before anything runs) while a check the
|
|
2502
|
+
* model raised is not in `acknowledged`. */
|
|
2503
|
+
async execute(call, acknowledged = []) {
|
|
2504
|
+
const callId = String(readField(call, "call_id", "callId"));
|
|
2505
|
+
const checks = (readField(
|
|
2506
|
+
call,
|
|
2507
|
+
"pending_safety_checks",
|
|
2508
|
+
"pendingSafetyChecks"
|
|
2509
|
+
) ?? []).map(safetyCheck);
|
|
2510
|
+
const png = await this.runCall(
|
|
2511
|
+
callId,
|
|
2512
|
+
_OpenAIComputer.actionsOf(call),
|
|
2513
|
+
checks,
|
|
2514
|
+
acknowledged
|
|
2515
|
+
);
|
|
2516
|
+
return {
|
|
2517
|
+
type: "computer_call_output",
|
|
2518
|
+
call_id: callId,
|
|
2519
|
+
output: {
|
|
2520
|
+
type: "computer_screenshot",
|
|
2521
|
+
image_url: dataUrl(png),
|
|
2522
|
+
detail: "original"
|
|
2523
|
+
},
|
|
2524
|
+
...checks.length > 0 ? { acknowledged_safety_checks: checks } : {}
|
|
2525
|
+
};
|
|
2526
|
+
}
|
|
2527
|
+
/** For `openai.tools.computer({ ...computer.aiSdk() })`: `execute` runs a
|
|
2528
|
+
* call's `actions` and returns the screenshot output. A call with pending
|
|
2529
|
+
* safety checks asks for approval first (`needsApproval`), so the AI SDK's
|
|
2530
|
+
* approval flow puts them in front of a person; once approved, `execute`
|
|
2531
|
+
* acknowledges them. */
|
|
2532
|
+
aiSdk() {
|
|
2533
|
+
return {
|
|
2534
|
+
needsApproval: (input) => (input.pendingSafetyChecks ?? []).length > 0,
|
|
2535
|
+
execute: (input) => this.serial(async () => {
|
|
2536
|
+
const checks = (input.pendingSafetyChecks ?? []).map(safetyCheck);
|
|
2537
|
+
const png = await this.runCall(
|
|
2538
|
+
"ai-sdk",
|
|
2539
|
+
input.actions ?? [],
|
|
2540
|
+
checks,
|
|
2541
|
+
checks
|
|
2542
|
+
);
|
|
2543
|
+
return {
|
|
2544
|
+
output: { type: "computer_screenshot", imageUrl: dataUrl(png) },
|
|
2545
|
+
...checks.length > 0 ? { acknowledgedSafetyChecks: checks } : {}
|
|
2546
|
+
};
|
|
2547
|
+
})
|
|
2548
|
+
};
|
|
2549
|
+
}
|
|
2550
|
+
/** The batch's actions, run after the safety checks clear; the screen after them. */
|
|
2551
|
+
async runCall(callId, rawActions, checks, acknowledged) {
|
|
2552
|
+
const cleared = new Set(acknowledged.map((c) => safetyCheck(c).id));
|
|
2553
|
+
const waiting = checks.filter((c) => !c.id || !cleared.has(c.id));
|
|
2554
|
+
if (waiting.length > 0) throw new PendingSafetyChecks(callId, waiting);
|
|
2555
|
+
const actions = rawActions.map((raw) => this.parse(raw));
|
|
2556
|
+
const results = await this.performAll(actions);
|
|
2557
|
+
const last = actions.at(-1);
|
|
2558
|
+
if (last?.name === "screenshot")
|
|
2559
|
+
return results.at(-1)?.image ?? Buffer.alloc(0);
|
|
2560
|
+
return this.screenshot();
|
|
2561
|
+
}
|
|
2562
|
+
};
|
|
2563
|
+
OpenAIPreviewComputer = class extends OpenAIComputer {
|
|
2564
|
+
tool() {
|
|
2565
|
+
return {
|
|
2566
|
+
type: "computer_use_preview",
|
|
2567
|
+
display_width: this.display.width,
|
|
2568
|
+
display_height: this.display.height,
|
|
2569
|
+
environment: "browser"
|
|
2570
|
+
};
|
|
2571
|
+
}
|
|
2572
|
+
};
|
|
2573
|
+
NativeComputer.register("openai", OpenAIComputer);
|
|
2574
|
+
NativeComputer.register("openai-preview", OpenAIPreviewComputer);
|
|
2575
|
+
}
|
|
2576
|
+
});
|
|
2577
|
+
|
|
2578
|
+
// src/worlds/nativeComputer/index.ts
|
|
2579
|
+
var init_nativeComputer = __esm({
|
|
2580
|
+
"src/worlds/nativeComputer/index.ts"() {
|
|
2581
|
+
"use strict";
|
|
2582
|
+
init_actions();
|
|
2583
|
+
init_base();
|
|
2584
|
+
init_display();
|
|
2585
|
+
init_keys();
|
|
2586
|
+
init_screen();
|
|
2587
|
+
init_trace();
|
|
2588
|
+
init_anthropic();
|
|
2589
|
+
init_openai();
|
|
2590
|
+
}
|
|
2591
|
+
});
|
|
2592
|
+
|
|
1326
2593
|
// src/worlds/sessionContract.ts
|
|
1327
2594
|
function serializeCallBody(body) {
|
|
1328
2595
|
const text2 = JSON.stringify(body);
|
|
@@ -1376,6 +2643,75 @@ var init_sessionContract = __esm({
|
|
|
1376
2643
|
}
|
|
1377
2644
|
});
|
|
1378
2645
|
|
|
2646
|
+
// src/tracing/session.ts
|
|
2647
|
+
var session_exports = {};
|
|
2648
|
+
__export(session_exports, {
|
|
2649
|
+
SESSION_ID_ATTRIBUTE: () => SESSION_ID_ATTRIBUTE,
|
|
2650
|
+
SessionSpanProcessor: () => SessionSpanProcessor,
|
|
2651
|
+
WORLD_SESSION_ID_ATTRIBUTE: () => WORLD_SESSION_ID_ATTRIBUTE,
|
|
2652
|
+
getAmbientSessionId: () => getAmbientSessionId,
|
|
2653
|
+
getCurrentWorldSessionId: () => getCurrentWorldSessionId,
|
|
2654
|
+
withSession: () => withSession,
|
|
2655
|
+
withWorldSession: () => withWorldSession
|
|
2656
|
+
});
|
|
2657
|
+
function getAmbientSessionId() {
|
|
2658
|
+
return currentSessionStorage.getStore();
|
|
2659
|
+
}
|
|
2660
|
+
function getCurrentWorldSessionId() {
|
|
2661
|
+
return currentWorldSessionStorage.getStore();
|
|
2662
|
+
}
|
|
2663
|
+
function runIn(storage, value, fn) {
|
|
2664
|
+
return new Promise((resolve11, reject) => {
|
|
2665
|
+
storage.run(value, () => {
|
|
2666
|
+
Promise.resolve().then(fn).then(resolve11, reject);
|
|
2667
|
+
});
|
|
2668
|
+
});
|
|
2669
|
+
}
|
|
2670
|
+
function withSession(sessionId, fn) {
|
|
2671
|
+
return runIn(currentSessionStorage, sessionId, fn);
|
|
2672
|
+
}
|
|
2673
|
+
function withWorldSession(worldSessionId, fn) {
|
|
2674
|
+
return runIn(
|
|
2675
|
+
currentWorldSessionStorage,
|
|
2676
|
+
worldSessionId,
|
|
2677
|
+
() => withSession(worldSessionId, fn)
|
|
2678
|
+
);
|
|
2679
|
+
}
|
|
2680
|
+
var import_async_hooks2, SESSION_ID_ATTRIBUTE, WORLD_SESSION_ID_ATTRIBUTE, processStorage, currentSessionStorage, currentWorldSessionStorage, SessionSpanProcessor;
|
|
2681
|
+
var init_session = __esm({
|
|
2682
|
+
"src/tracing/session.ts"() {
|
|
2683
|
+
"use strict";
|
|
2684
|
+
import_async_hooks2 = require("async_hooks");
|
|
2685
|
+
SESSION_ID_ATTRIBUTE = "gateway.session.id";
|
|
2686
|
+
WORLD_SESSION_ID_ATTRIBUTE = "gateway.trace.metadata.world_session_id";
|
|
2687
|
+
processStorage = (name) => {
|
|
2688
|
+
const key2 = /* @__PURE__ */ Symbol.for(`@withgateway/sdk/${name}`);
|
|
2689
|
+
const slots = globalThis;
|
|
2690
|
+
slots[key2] ??= new import_async_hooks2.AsyncLocalStorage();
|
|
2691
|
+
return slots[key2];
|
|
2692
|
+
};
|
|
2693
|
+
currentSessionStorage = processStorage("session-storage");
|
|
2694
|
+
currentWorldSessionStorage = processStorage("world-session-storage");
|
|
2695
|
+
SessionSpanProcessor = class {
|
|
2696
|
+
onStart(span, _parentContext) {
|
|
2697
|
+
const worldSessionId = getCurrentWorldSessionId();
|
|
2698
|
+
if (worldSessionId)
|
|
2699
|
+
span.setAttribute(WORLD_SESSION_ID_ATTRIBUTE, worldSessionId);
|
|
2700
|
+
const sessionId = getAmbientSessionId();
|
|
2701
|
+
if (!sessionId || span.attributes?.[SESSION_ID_ATTRIBUTE] !== void 0)
|
|
2702
|
+
return;
|
|
2703
|
+
span.setAttribute(SESSION_ID_ATTRIBUTE, sessionId);
|
|
2704
|
+
}
|
|
2705
|
+
onEnd(_span) {
|
|
2706
|
+
}
|
|
2707
|
+
async shutdown() {
|
|
2708
|
+
}
|
|
2709
|
+
async forceFlush() {
|
|
2710
|
+
}
|
|
2711
|
+
};
|
|
2712
|
+
}
|
|
2713
|
+
});
|
|
2714
|
+
|
|
1379
2715
|
// src/worlds/taskRef.ts
|
|
1380
2716
|
var isTaskIdRef, isTaskSpec, taskLabel, assertTaskRef;
|
|
1381
2717
|
var init_taskRef = __esm({
|
|
@@ -1400,8 +2736,8 @@ var init_taskRef = __esm({
|
|
|
1400
2736
|
});
|
|
1401
2737
|
|
|
1402
2738
|
// src/worlds/session.ts
|
|
1403
|
-
var
|
|
1404
|
-
__export(
|
|
2739
|
+
var session_exports2 = {};
|
|
2740
|
+
__export(session_exports2, {
|
|
1405
2741
|
WorldSession: () => WorldSession,
|
|
1406
2742
|
WorldSessionCallError: () => WorldSessionCallError,
|
|
1407
2743
|
WorldSessionTimeout: () => WorldSessionTimeout,
|
|
@@ -1454,7 +2790,7 @@ function schemaFromSignature(spec) {
|
|
|
1454
2790
|
};
|
|
1455
2791
|
const inside = /\(([\s\S]*)\)\s*$/.exec(spec.signature.trim())?.[1] ?? "";
|
|
1456
2792
|
const properties = {};
|
|
1457
|
-
const
|
|
2793
|
+
const required2 = [];
|
|
1458
2794
|
const params = [];
|
|
1459
2795
|
let depth = 0;
|
|
1460
2796
|
let current = "";
|
|
@@ -1475,7 +2811,7 @@ function schemaFromSignature(spec) {
|
|
|
1475
2811
|
if (!name) continue;
|
|
1476
2812
|
if (eq === -1) {
|
|
1477
2813
|
properties[name] = { type: "string" };
|
|
1478
|
-
|
|
2814
|
+
required2.push(name);
|
|
1479
2815
|
continue;
|
|
1480
2816
|
}
|
|
1481
2817
|
const value = param.slice(eq + 1).trim();
|
|
@@ -1489,7 +2825,7 @@ function schemaFromSignature(spec) {
|
|
|
1489
2825
|
function: {
|
|
1490
2826
|
name: modelToolName(spec.name),
|
|
1491
2827
|
description: spec.doc ?? spec.name,
|
|
1492
|
-
parameters: { type: "object", properties, required }
|
|
2828
|
+
parameters: { type: "object", properties, required: required2 }
|
|
1493
2829
|
}
|
|
1494
2830
|
};
|
|
1495
2831
|
}
|
|
@@ -1558,13 +2894,16 @@ async function runSessions(opts) {
|
|
|
1558
2894
|
task = taskLabel(taskRef, session.taskInfo);
|
|
1559
2895
|
await session.ready();
|
|
1560
2896
|
const toolkit = await session.toolkit();
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
2897
|
+
const live = session;
|
|
2898
|
+
await live.withTraceContext(
|
|
2899
|
+
() => opts.agent({
|
|
2900
|
+
session: live,
|
|
2901
|
+
toolkit,
|
|
2902
|
+
instruction: live.instruction ?? (isTaskSpec(taskRef) ? taskRef.instruction : task),
|
|
2903
|
+
task,
|
|
2904
|
+
taskRef
|
|
2905
|
+
})
|
|
2906
|
+
);
|
|
1568
2907
|
const graded = await session.grade();
|
|
1569
2908
|
const result = {
|
|
1570
2909
|
task,
|
|
@@ -1601,14 +2940,16 @@ async function runSessions(opts) {
|
|
|
1601
2940
|
passed: failed === 0 && (opts.failUnder === void 0 || mean >= opts.failUnder)
|
|
1602
2941
|
};
|
|
1603
2942
|
}
|
|
1604
|
-
var
|
|
1605
|
-
var
|
|
2943
|
+
var import_node_crypto2, READY_TIMEOUT_MS, READY_POLL_MS, CALL_TIMEOUT_MS, CALL_POLL_MS, JUDGED_GRADE_TIMEOUT_MS, JUDGED_GRADE_POLL_MS, EXPORT_PAGE, sleep2, modelToolName, WorldSessionTimeout, WorldSessionCallError, WorldSession, OPEN_SESSION_OPTION_KEYS, isOpenSessionOptions;
|
|
2944
|
+
var init_session2 = __esm({
|
|
1606
2945
|
"src/worlds/session.ts"() {
|
|
1607
2946
|
"use strict";
|
|
1608
|
-
|
|
2947
|
+
import_node_crypto2 = require("crypto");
|
|
1609
2948
|
init_worlds();
|
|
1610
2949
|
init_browser();
|
|
2950
|
+
init_nativeComputer();
|
|
1611
2951
|
init_sessionContract();
|
|
2952
|
+
init_session();
|
|
1612
2953
|
init_taskRef();
|
|
1613
2954
|
init_taskRef();
|
|
1614
2955
|
READY_TIMEOUT_MS = 10 * 6e4;
|
|
@@ -1742,7 +3083,7 @@ var init_session = __esm({
|
|
|
1742
3083
|
/** The reporter `browser()` uses; exposed for a page you drive yourself. */
|
|
1743
3084
|
browserRecorder(agentId) {
|
|
1744
3085
|
const path16 = `/api/public/world-sessions/${encodeURIComponent(this.sessionId)}/browser-events`;
|
|
1745
|
-
const id = agentId ?? process.env.GATEWAY_AGENT_ID ?? `agent-${(0,
|
|
3086
|
+
const id = agentId ?? process.env.GATEWAY_AGENT_ID ?? `agent-${(0, import_node_crypto2.randomUUID)().replace(/-/g, "").slice(0, 8)}`;
|
|
1746
3087
|
return new BrowserActionRecorder(
|
|
1747
3088
|
async (events) => {
|
|
1748
3089
|
await apiRequest(this.options, "POST", path16, { events });
|
|
@@ -1762,6 +3103,12 @@ var init_session = __esm({
|
|
|
1762
3103
|
computerUseTools(browser) {
|
|
1763
3104
|
return computerUseToolkit(browser);
|
|
1764
3105
|
}
|
|
3106
|
+
/** The browser as a provider's own pixel-based computer-use tool: `anthropic`
|
|
3107
|
+
* (`computer_toolset_20260801`), `openai` (Responses `computer`),
|
|
3108
|
+
* `anthropic-computer-20251124` or `openai-preview`. See `nativeComputer/`. */
|
|
3109
|
+
nativeComputer(browser, provider = "anthropic", options = {}) {
|
|
3110
|
+
return NativeComputer.forProvider(provider, browser, options);
|
|
3111
|
+
}
|
|
1765
3112
|
/** The session's latest platform state (one request, no waiting). */
|
|
1766
3113
|
async status() {
|
|
1767
3114
|
const fresh = await apiRequest(
|
|
@@ -1996,6 +3343,21 @@ var init_session = __esm({
|
|
|
1996
3343
|
{ keepWarm: opts.keepWarm ?? false }
|
|
1997
3344
|
);
|
|
1998
3345
|
}
|
|
3346
|
+
/**
|
|
3347
|
+
* Run `fn` as work inside this session: spans it records take `sessionId`
|
|
3348
|
+
* as their session id and carry `world_session_id` trace metadata, so the
|
|
3349
|
+
* agent's traces land in the same session as the platform's traces of this
|
|
3350
|
+
* session's tool calls. A `withSession()` block inside still wins for the
|
|
3351
|
+
* session id. No effect before `tracing.init()`. `runSessions` wraps each
|
|
3352
|
+
* agent call in it.
|
|
3353
|
+
*
|
|
3354
|
+
* ```typescript
|
|
3355
|
+
* await session.withTraceContext(() => myAgent(toolkit, session.instruction));
|
|
3356
|
+
* ```
|
|
3357
|
+
*/
|
|
3358
|
+
withTraceContext(fn) {
|
|
3359
|
+
return withWorldSession(this.sessionId, fn);
|
|
3360
|
+
}
|
|
1999
3361
|
};
|
|
2000
3362
|
OPEN_SESSION_OPTION_KEYS = /* @__PURE__ */ new Set([
|
|
2001
3363
|
"task",
|
|
@@ -2145,7 +3507,11 @@ function fromResponse(answer, options) {
|
|
|
2145
3507
|
const worlds = {};
|
|
2146
3508
|
for (const [alias, state2] of Object.entries(answer.sessions)) {
|
|
2147
3509
|
sessions2[alias] = new WorldSession(state2.sessionId, state2, options);
|
|
2148
|
-
worlds[alias] = {
|
|
3510
|
+
worlds[alias] = {
|
|
3511
|
+
slug: state2.slug,
|
|
3512
|
+
ref: state2.ref,
|
|
3513
|
+
private: state2.private ?? null
|
|
3514
|
+
};
|
|
2149
3515
|
}
|
|
2150
3516
|
return new TaskSessions(
|
|
2151
3517
|
answer.taskId,
|
|
@@ -2219,6 +3585,7 @@ async function attachTask(taskId, options = {}) {
|
|
|
2219
3585
|
{
|
|
2220
3586
|
slug: row.slug ?? "",
|
|
2221
3587
|
ref: null,
|
|
3588
|
+
private: null,
|
|
2222
3589
|
versionId: row.versionId,
|
|
2223
3590
|
sessionId: row.sessionId,
|
|
2224
3591
|
ready: row.ready,
|
|
@@ -2248,7 +3615,7 @@ async function attachManifest(manifest, options = {}) {
|
|
|
2248
3615
|
Object.fromEntries(
|
|
2249
3616
|
Object.entries(manifest.sessions).map(([alias, entry]) => [
|
|
2250
3617
|
alias,
|
|
2251
|
-
{ slug: entry.slug, ref: entry.ref }
|
|
3618
|
+
{ slug: entry.slug, ref: entry.ref, private: entry.private ?? null }
|
|
2252
3619
|
])
|
|
2253
3620
|
)
|
|
2254
3621
|
);
|
|
@@ -2262,12 +3629,13 @@ var init_taskSessions = __esm({
|
|
|
2262
3629
|
"use strict";
|
|
2263
3630
|
init_worlds();
|
|
2264
3631
|
init_browser();
|
|
2265
|
-
|
|
3632
|
+
init_session2();
|
|
2266
3633
|
TASK_SESSIONS = "/api/public/world-task-sessions";
|
|
2267
3634
|
VERIFIER_REWARD_PREFIX = "x.";
|
|
2268
3635
|
manifestSession = (s, state2, world) => ({
|
|
2269
3636
|
slug: world.slug,
|
|
2270
3637
|
ref: world.ref,
|
|
3638
|
+
private: world.private,
|
|
2271
3639
|
versionId: state2.versionId,
|
|
2272
3640
|
sessionId: state2.sessionId,
|
|
2273
3641
|
ready: state2.ready,
|
|
@@ -2302,10 +3670,10 @@ var init_taskSessions = __esm({
|
|
|
2302
3670
|
sessions;
|
|
2303
3671
|
worlds;
|
|
2304
3672
|
hash;
|
|
2305
|
-
/** This alias's
|
|
2306
|
-
*
|
|
3673
|
+
/** This alias's world as recorded at open/attach — what a `TaskRun`
|
|
3674
|
+
* filing needs to name, without exposing the whole map. */
|
|
2307
3675
|
worldRef(alias) {
|
|
2308
|
-
return this.worlds[alias] ?? { slug: "", ref: null };
|
|
3676
|
+
return this.worlds[alias] ?? { slug: "", ref: null, private: null };
|
|
2309
3677
|
}
|
|
2310
3678
|
/** The aliases, in the spec's order. */
|
|
2311
3679
|
get aliases() {
|
|
@@ -2508,15 +3876,15 @@ function debugLog(message, ...args) {
|
|
|
2508
3876
|
console.debug(`[gatewaysdk.tracing] ${message}`, ...args);
|
|
2509
3877
|
}
|
|
2510
3878
|
}
|
|
2511
|
-
var
|
|
3879
|
+
var import_async_hooks3, import_api2, USER_ID_ATTRIBUTE, currentUserStorage, IdentitySpanProcessor;
|
|
2512
3880
|
var init_identity = __esm({
|
|
2513
3881
|
"src/tracing/identity.ts"() {
|
|
2514
3882
|
"use strict";
|
|
2515
|
-
|
|
3883
|
+
import_async_hooks3 = require("async_hooks");
|
|
2516
3884
|
import_api2 = require("@opentelemetry/api");
|
|
2517
3885
|
init_users();
|
|
2518
3886
|
USER_ID_ATTRIBUTE = "gateway.user.id";
|
|
2519
|
-
currentUserStorage = new
|
|
3887
|
+
currentUserStorage = new import_async_hooks3.AsyncLocalStorage();
|
|
2520
3888
|
IdentitySpanProcessor = class {
|
|
2521
3889
|
onStart(span, _parentContext) {
|
|
2522
3890
|
const userId = resolveUserId();
|
|
@@ -2534,43 +3902,224 @@ var init_identity = __esm({
|
|
|
2534
3902
|
}
|
|
2535
3903
|
});
|
|
2536
3904
|
|
|
2537
|
-
// src/tracing/
|
|
2538
|
-
|
|
2539
|
-
|
|
2540
|
-
|
|
2541
|
-
|
|
2542
|
-
|
|
2543
|
-
|
|
2544
|
-
}
|
|
2545
|
-
|
|
2546
|
-
return
|
|
3905
|
+
// src/tracing/secrets.ts
|
|
3906
|
+
function jsonOrUndefined(text2) {
|
|
3907
|
+
let parsed;
|
|
3908
|
+
try {
|
|
3909
|
+
parsed = JSON.parse(text2);
|
|
3910
|
+
} catch {
|
|
3911
|
+
return void 0;
|
|
3912
|
+
}
|
|
3913
|
+
if (typeof parsed === "string") return parsed;
|
|
3914
|
+
return parsed !== null && typeof parsed === "object" ? parsed : void 0;
|
|
2547
3915
|
}
|
|
2548
|
-
function
|
|
2549
|
-
return
|
|
2550
|
-
|
|
2551
|
-
|
|
2552
|
-
|
|
3916
|
+
function encodings(value) {
|
|
3917
|
+
return [value, percentEncoded(value), JSON.stringify(value).slice(1, -1)];
|
|
3918
|
+
}
|
|
3919
|
+
function percentEncoded(value) {
|
|
3920
|
+
try {
|
|
3921
|
+
return encodeURIComponent(value);
|
|
3922
|
+
} catch {
|
|
3923
|
+
return value;
|
|
3924
|
+
}
|
|
3925
|
+
}
|
|
3926
|
+
function union(sets) {
|
|
3927
|
+
return new Set(sets.flatMap((set) => [...set]));
|
|
3928
|
+
}
|
|
3929
|
+
function leaves(value) {
|
|
3930
|
+
if (typeof value === "string") {
|
|
3931
|
+
return [...value].length >= MIN_SECRET_LENGTH ? /* @__PURE__ */ new Set([value]) : /* @__PURE__ */ new Set();
|
|
3932
|
+
}
|
|
3933
|
+
if (Array.isArray(value)) return union(value.map(leaves));
|
|
3934
|
+
if (value === null || typeof value !== "object") return /* @__PURE__ */ new Set();
|
|
3935
|
+
return union(Object.values(value).map(leaves));
|
|
3936
|
+
}
|
|
3937
|
+
function sameAttributes(before, after) {
|
|
3938
|
+
const keys = Object.keys(before);
|
|
3939
|
+
if (keys.length !== Object.keys(after).length) return false;
|
|
3940
|
+
return keys.every(
|
|
3941
|
+
(key2) => before[key2] === after[key2] || sameArray(before[key2], after[key2])
|
|
3942
|
+
);
|
|
3943
|
+
}
|
|
3944
|
+
function sameArray(before, after) {
|
|
3945
|
+
if (!Array.isArray(before) || !Array.isArray(after)) return false;
|
|
3946
|
+
return before.length === after.length && before.every((item, i) => item === after[i]);
|
|
3947
|
+
}
|
|
3948
|
+
function scrubbedRead(reads, property) {
|
|
3949
|
+
return typeof property === "string" && property in reads ? reads[property] : void 0;
|
|
3950
|
+
}
|
|
3951
|
+
function viewOf(span, reads) {
|
|
3952
|
+
const view = new Proxy(span, {
|
|
3953
|
+
get(target, property) {
|
|
3954
|
+
const read = scrubbedRead(reads, property);
|
|
3955
|
+
if (read) return read();
|
|
3956
|
+
const value = Reflect.get(target, property, target);
|
|
3957
|
+
if (typeof value !== "function") return value;
|
|
3958
|
+
return (...args) => {
|
|
3959
|
+
const result = value.apply(target, args);
|
|
3960
|
+
return result === target ? view : result;
|
|
3961
|
+
};
|
|
3962
|
+
},
|
|
3963
|
+
getOwnPropertyDescriptor(target, property) {
|
|
3964
|
+
const descriptor = Reflect.getOwnPropertyDescriptor(target, property);
|
|
3965
|
+
const read = scrubbedRead(reads, property);
|
|
3966
|
+
if (!read || !descriptor || !("value" in descriptor)) return descriptor;
|
|
3967
|
+
return { ...descriptor, value: read() };
|
|
3968
|
+
}
|
|
2553
3969
|
});
|
|
3970
|
+
return view;
|
|
2554
3971
|
}
|
|
2555
|
-
var
|
|
2556
|
-
var
|
|
2557
|
-
"src/tracing/
|
|
3972
|
+
var SECRET_KEYS, REDACTED2, MIN_SECRET_LENGTH, SpanSecrets, SPAN_SECRETS, SecretRedactingSpanProcessor;
|
|
3973
|
+
var init_secrets = __esm({
|
|
3974
|
+
"src/tracing/secrets.ts"() {
|
|
2558
3975
|
"use strict";
|
|
2559
|
-
|
|
2560
|
-
|
|
2561
|
-
|
|
2562
|
-
|
|
2563
|
-
|
|
2564
|
-
|
|
2565
|
-
|
|
2566
|
-
|
|
3976
|
+
SECRET_KEYS = /* @__PURE__ */ new Set([
|
|
3977
|
+
"authorization_token",
|
|
3978
|
+
"authorizationToken"
|
|
3979
|
+
]);
|
|
3980
|
+
REDACTED2 = "[redacted: holds a credential]";
|
|
3981
|
+
MIN_SECRET_LENGTH = 8;
|
|
3982
|
+
SpanSecrets = class {
|
|
3983
|
+
constructor(keys = SECRET_KEYS) {
|
|
3984
|
+
this.keys = keys;
|
|
3985
|
+
}
|
|
3986
|
+
keys;
|
|
3987
|
+
isSecret(key2) {
|
|
3988
|
+
return this.keys.has(key2);
|
|
3989
|
+
}
|
|
3990
|
+
drops(attribute) {
|
|
3991
|
+
return this.mentions(attribute);
|
|
3992
|
+
}
|
|
3993
|
+
strip(value) {
|
|
3994
|
+
if (typeof value === "string") return this.stripNested(value);
|
|
3995
|
+
if (Array.isArray(value)) return value.map((item) => this.strip(item));
|
|
3996
|
+
if (value === null || typeof value !== "object") return value;
|
|
3997
|
+
return Object.fromEntries(
|
|
3998
|
+
Object.entries(value).filter(([key2]) => !this.isSecret(key2)).map(([key2, item]) => [key2, this.strip(item)])
|
|
3999
|
+
);
|
|
4000
|
+
}
|
|
4001
|
+
scrubAttribute(value) {
|
|
4002
|
+
try {
|
|
4003
|
+
return this.scrubbedValue(value);
|
|
4004
|
+
} catch {
|
|
4005
|
+
return Array.isArray(value) ? [REDACTED2] : REDACTED2;
|
|
2567
4006
|
}
|
|
2568
4007
|
}
|
|
2569
|
-
|
|
4008
|
+
scrubbedValue(value) {
|
|
4009
|
+
if (typeof value === "string") return this.scrubbedText(value);
|
|
4010
|
+
if (!Array.isArray(value)) return value;
|
|
4011
|
+
const results = value.map(
|
|
4012
|
+
(item) => typeof item === "string" ? this.cleaned(item) : { text: item, removed: /* @__PURE__ */ new Set() }
|
|
4013
|
+
);
|
|
4014
|
+
const removed = new Set(results.flatMap((r) => [...r.removed]));
|
|
4015
|
+
const scrubbed = results.map((r) => r.text);
|
|
4016
|
+
const withheld = scrubbed.some(
|
|
4017
|
+
(item) => typeof item === "string" && this.carries(item, removed)
|
|
4018
|
+
);
|
|
4019
|
+
return withheld ? [REDACTED2] : scrubbed;
|
|
2570
4020
|
}
|
|
2571
|
-
|
|
4021
|
+
scrubAttributes(attributes) {
|
|
4022
|
+
return Object.fromEntries(
|
|
4023
|
+
Object.entries(attributes).filter(([key2]) => !this.drops(key2)).map(([key2, value]) => [key2, this.scrubAttribute(value)])
|
|
4024
|
+
);
|
|
2572
4025
|
}
|
|
2573
|
-
|
|
4026
|
+
mentions(text2) {
|
|
4027
|
+
return [...this.keys].some((key2) => text2.includes(key2));
|
|
4028
|
+
}
|
|
4029
|
+
scrubbedText(text2) {
|
|
4030
|
+
const { text: cleaned, removed } = this.cleaned(text2);
|
|
4031
|
+
return this.carries(cleaned, removed) ? REDACTED2 : cleaned;
|
|
4032
|
+
}
|
|
4033
|
+
cleaned(text2) {
|
|
4034
|
+
if (!this.mentions(text2)) return { text: text2, removed: /* @__PURE__ */ new Set() };
|
|
4035
|
+
const parsed = jsonOrUndefined(text2);
|
|
4036
|
+
if (parsed === void 0) return { text: REDACTED2, removed: /* @__PURE__ */ new Set() };
|
|
4037
|
+
return {
|
|
4038
|
+
text: JSON.stringify(this.strip(parsed)),
|
|
4039
|
+
removed: this.removed(parsed)
|
|
4040
|
+
};
|
|
4041
|
+
}
|
|
4042
|
+
carries(text2, removed) {
|
|
4043
|
+
if (text2 === REDACTED2 || this.mentions(text2)) return true;
|
|
4044
|
+
return [...removed].some(
|
|
4045
|
+
(value) => encodings(value).some((form) => text2.includes(form))
|
|
4046
|
+
);
|
|
4047
|
+
}
|
|
4048
|
+
removed(value) {
|
|
4049
|
+
if (typeof value === "string") {
|
|
4050
|
+
const nested = this.mentions(value) ? jsonOrUndefined(value) : void 0;
|
|
4051
|
+
return nested === void 0 ? /* @__PURE__ */ new Set() : this.removed(nested);
|
|
4052
|
+
}
|
|
4053
|
+
if (Array.isArray(value)) return union(value.map((v) => this.removed(v)));
|
|
4054
|
+
if (value === null || typeof value !== "object") return /* @__PURE__ */ new Set();
|
|
4055
|
+
return union(
|
|
4056
|
+
Object.entries(value).map(
|
|
4057
|
+
([key2, item]) => this.isSecret(key2) ? leaves(item) : this.removed(item)
|
|
4058
|
+
)
|
|
4059
|
+
);
|
|
4060
|
+
}
|
|
4061
|
+
stripNested(text2) {
|
|
4062
|
+
if (!this.mentions(text2)) return text2;
|
|
4063
|
+
const parsed = jsonOrUndefined(text2);
|
|
4064
|
+
if (parsed === void 0) return text2;
|
|
4065
|
+
return JSON.stringify(this.strip(parsed));
|
|
4066
|
+
}
|
|
4067
|
+
};
|
|
4068
|
+
SPAN_SECRETS = new SpanSecrets();
|
|
4069
|
+
SecretRedactingSpanProcessor = class {
|
|
4070
|
+
constructor(inner, secrets = SPAN_SECRETS) {
|
|
4071
|
+
this.inner = inner;
|
|
4072
|
+
this.secrets = secrets;
|
|
4073
|
+
}
|
|
4074
|
+
inner;
|
|
4075
|
+
secrets;
|
|
4076
|
+
views = /* @__PURE__ */ new WeakMap();
|
|
4077
|
+
onStart(span, parentContext) {
|
|
4078
|
+
this.inner.onStart(this.viewFor(span), parentContext);
|
|
4079
|
+
}
|
|
4080
|
+
onEnd(span) {
|
|
4081
|
+
const view = this.viewFor(span);
|
|
4082
|
+
try {
|
|
4083
|
+
void [view.attributes, view.events, view.status];
|
|
4084
|
+
} catch (error) {
|
|
4085
|
+
console.warn(
|
|
4086
|
+
`[gatewaysdk.tracing] Dropped span "${span.name}": could not redact it: ${error?.name}`
|
|
4087
|
+
);
|
|
4088
|
+
return;
|
|
4089
|
+
}
|
|
4090
|
+
this.inner.onEnd(view);
|
|
4091
|
+
}
|
|
4092
|
+
viewFor(span) {
|
|
4093
|
+
const known = this.views.get(span);
|
|
4094
|
+
if (known) return known;
|
|
4095
|
+
const view = viewOf(span, {
|
|
4096
|
+
attributes: () => this.scrubbedAttributes(span.attributes),
|
|
4097
|
+
events: () => span.events.map((event) => this.scrubbedEvent(event)),
|
|
4098
|
+
status: () => this.scrubbedStatus(span.status)
|
|
4099
|
+
});
|
|
4100
|
+
this.views.set(span, view);
|
|
4101
|
+
return view;
|
|
4102
|
+
}
|
|
4103
|
+
forceFlush() {
|
|
4104
|
+
return this.inner.forceFlush();
|
|
4105
|
+
}
|
|
4106
|
+
shutdown() {
|
|
4107
|
+
return this.inner.shutdown();
|
|
4108
|
+
}
|
|
4109
|
+
scrubbedAttributes(attributes) {
|
|
4110
|
+
const clean = this.secrets.scrubAttributes(attributes);
|
|
4111
|
+
return sameAttributes(attributes, clean) ? attributes : clean;
|
|
4112
|
+
}
|
|
4113
|
+
scrubbedStatus(status) {
|
|
4114
|
+
if (!status.message) return status;
|
|
4115
|
+
const message = this.secrets.scrubAttribute(status.message);
|
|
4116
|
+
return message === status.message ? status : { ...status, message };
|
|
4117
|
+
}
|
|
4118
|
+
scrubbedEvent(event) {
|
|
4119
|
+
if (!event.attributes) return event;
|
|
4120
|
+
const attributes = this.scrubbedAttributes(event.attributes);
|
|
4121
|
+
if (attributes === event.attributes) return event;
|
|
4122
|
+
return { ...event, attributes };
|
|
2574
4123
|
}
|
|
2575
4124
|
};
|
|
2576
4125
|
}
|
|
@@ -2581,7 +4130,7 @@ var require_package = __commonJS({
|
|
|
2581
4130
|
"package.json"(exports2, module2) {
|
|
2582
4131
|
module2.exports = {
|
|
2583
4132
|
name: "@withgateway/sdk",
|
|
2584
|
-
version: "0.
|
|
4133
|
+
version: "0.3.0",
|
|
2585
4134
|
description: "Gateway SDK for TypeScript - A/B experiments, tracing, and observability",
|
|
2586
4135
|
main: "./dist/index.js",
|
|
2587
4136
|
module: "./dist/index.mjs",
|
|
@@ -2792,7 +4341,7 @@ function canonicalJson(value) {
|
|
|
2792
4341
|
return `{${entries.map(([k, v]) => `${JSON.stringify(k)}:${canonicalJson(v)}`).join(",")}}`;
|
|
2793
4342
|
}
|
|
2794
4343
|
function sha256(text2) {
|
|
2795
|
-
return `sha256:${(0,
|
|
4344
|
+
return `sha256:${(0, import_node_crypto3.createHash)("sha256").update(text2).digest("hex")}`;
|
|
2796
4345
|
}
|
|
2797
4346
|
function captureSource() {
|
|
2798
4347
|
const stack = new Error().stack?.split("\n") ?? [];
|
|
@@ -3052,11 +4601,11 @@ async function registerBuild(params) {
|
|
|
3052
4601
|
);
|
|
3053
4602
|
}
|
|
3054
4603
|
}
|
|
3055
|
-
var
|
|
4604
|
+
var import_node_crypto3, registeredTools, registeredPrompts, registeredSkills, registeredArtifacts, activeBuilds, reRegisterTimer, RE_REGISTER_DEBOUNCE_MS;
|
|
3056
4605
|
var init_build = __esm({
|
|
3057
4606
|
"src/build/index.ts"() {
|
|
3058
4607
|
"use strict";
|
|
3059
|
-
|
|
4608
|
+
import_node_crypto3 = require("crypto");
|
|
3060
4609
|
registeredTools = /* @__PURE__ */ new Map();
|
|
3061
4610
|
registeredPrompts = /* @__PURE__ */ new Map();
|
|
3062
4611
|
registeredSkills = /* @__PURE__ */ new Map();
|
|
@@ -3188,7 +4737,7 @@ function buildProvider(config, logFn) {
|
|
|
3188
4737
|
const spanProcessors = [];
|
|
3189
4738
|
if (config.customSpanProcessors) {
|
|
3190
4739
|
for (const sp of config.customSpanProcessors) {
|
|
3191
|
-
spanProcessors.push(sp);
|
|
4740
|
+
spanProcessors.push(new SecretRedactingSpanProcessor(sp));
|
|
3192
4741
|
logFn(
|
|
3193
4742
|
"Added custom span processor: %s",
|
|
3194
4743
|
sp.constructor?.name ?? "unknown"
|
|
@@ -3207,7 +4756,11 @@ function buildProvider(config, logFn) {
|
|
|
3207
4756
|
if (config.batch?.maxExportBatchSize) {
|
|
3208
4757
|
batchConfig.maxExportBatchSize = config.batch.maxExportBatchSize;
|
|
3209
4758
|
}
|
|
3210
|
-
spanProcessors.push(
|
|
4759
|
+
spanProcessors.push(
|
|
4760
|
+
new SecretRedactingSpanProcessor(
|
|
4761
|
+
new BatchSpanProcessor(exporter, batchConfig)
|
|
4762
|
+
)
|
|
4763
|
+
);
|
|
3211
4764
|
let provider = new NodeTracerProvider({
|
|
3212
4765
|
resource: createResource(resourceAttrs)
|
|
3213
4766
|
});
|
|
@@ -3345,7 +4898,8 @@ var init_init = __esm({
|
|
|
3345
4898
|
"src/tracing/init.ts"() {
|
|
3346
4899
|
"use strict";
|
|
3347
4900
|
init_identity();
|
|
3348
|
-
|
|
4901
|
+
init_secrets();
|
|
4902
|
+
init_session();
|
|
3349
4903
|
init_scores();
|
|
3350
4904
|
init_build();
|
|
3351
4905
|
ENV_VARS = {
|
|
@@ -3460,7 +5014,7 @@ function reportFromResult(result) {
|
|
|
3460
5014
|
return { report, extra };
|
|
3461
5015
|
}
|
|
3462
5016
|
async function runTask(ref, agent, opts) {
|
|
3463
|
-
const runId = `wtr-${(0,
|
|
5017
|
+
const runId = `wtr-${(0, import_node_crypto4.randomBytes)(6).toString("hex")}`;
|
|
3464
5018
|
const outDir = opts.outDir ?? "runs";
|
|
3465
5019
|
const runDir = path.join(outDir, runId);
|
|
3466
5020
|
fs.mkdirSync(runDir, { recursive: true });
|
|
@@ -3498,7 +5052,7 @@ async function runTask(ref, agent, opts) {
|
|
|
3498
5052
|
let extra = {};
|
|
3499
5053
|
try {
|
|
3500
5054
|
const invoke = () => agent(taskRun);
|
|
3501
|
-
const result = traced ? await (await Promise.resolve().then(() => (
|
|
5055
|
+
const result = traced ? await (await Promise.resolve().then(() => (init_session(), session_exports))).withSession(runId, invoke) : await invoke();
|
|
3502
5056
|
({ report, extra } = reportFromResult(result));
|
|
3503
5057
|
} catch (error) {
|
|
3504
5058
|
const message = (error instanceof Error ? error.message : String(error)) || "Unknown error";
|
|
@@ -3565,16 +5119,16 @@ async function runTask(ref, agent, opts) {
|
|
|
3565
5119
|
}
|
|
3566
5120
|
}
|
|
3567
5121
|
}
|
|
3568
|
-
var
|
|
5122
|
+
var import_node_crypto4, fs, path, TaskRun, describeValue, RESULT_CONTRACT;
|
|
3569
5123
|
var init_taskRun = __esm({
|
|
3570
5124
|
"src/worlds/taskRun.ts"() {
|
|
3571
5125
|
"use strict";
|
|
3572
|
-
|
|
5126
|
+
import_node_crypto4 = require("crypto");
|
|
3573
5127
|
fs = __toESM(require("fs"));
|
|
3574
5128
|
path = __toESM(require("path"));
|
|
3575
5129
|
init_browser();
|
|
3576
5130
|
init_evals();
|
|
3577
|
-
|
|
5131
|
+
init_session2();
|
|
3578
5132
|
init_taskSessions();
|
|
3579
5133
|
TaskRun = class {
|
|
3580
5134
|
constructor(runId, instruction, model, sessions2, manifest) {
|
|
@@ -3883,11 +5437,11 @@ var init_checkoutTarget = __esm({
|
|
|
3883
5437
|
});
|
|
3884
5438
|
|
|
3885
5439
|
// src/worlds/worldDir.ts
|
|
3886
|
-
var
|
|
5440
|
+
var import_node_crypto5, fs3, path3, WORLD_MANIFEST, API_BUNDLE_MANIFEST, BUNDLED_WORLD_PREFIX, CONNECTOR_SPEC, PYPROJECT, BENCHMARK_CONFIG, WORLD_SCHEMA_MARKERS, WORLD_ROOT_MARKERS, BROAD_ROOT_MARKERS, SKIPPED_DIRS, V1_DEP, V1_IMPORT, V1_TASKSET, HARBOR_TASK, skippedDir, byCodePoint, WorldDir;
|
|
3887
5441
|
var init_worldDir = __esm({
|
|
3888
5442
|
"src/worlds/worldDir.ts"() {
|
|
3889
5443
|
"use strict";
|
|
3890
|
-
|
|
5444
|
+
import_node_crypto5 = require("crypto");
|
|
3891
5445
|
fs3 = __toESM(require("fs"));
|
|
3892
5446
|
path3 = __toESM(require("path"));
|
|
3893
5447
|
WORLD_MANIFEST = "gateway-env.toml";
|
|
@@ -3993,7 +5547,7 @@ var init_worldDir = __esm({
|
|
|
3993
5547
|
* sorted order: the version's identity, byte-compatible with
|
|
3994
5548
|
* `_archive.compute_content_hash` and Prime Intellect. */
|
|
3995
5549
|
get contentHash() {
|
|
3996
|
-
const hasher = (0,
|
|
5550
|
+
const hasher = (0, import_node_crypto5.createHash)("sha256");
|
|
3997
5551
|
for (const rel of this.archivePaths) {
|
|
3998
5552
|
hasher.update(Buffer.from(`file:${rel}`, "utf-8"));
|
|
3999
5553
|
hasher.update(fs3.readFileSync(path3.join(this.dir, rel)));
|
|
@@ -4297,7 +5851,7 @@ function writeLocalMeta(dir, meta) {
|
|
|
4297
5851
|
function snapshotTreeHashes(dir) {
|
|
4298
5852
|
const out = {};
|
|
4299
5853
|
for (const relPath of collectArchiveRelPaths(dir)) {
|
|
4300
|
-
out[relPath] = (0,
|
|
5854
|
+
out[relPath] = (0, import_node_crypto6.createHash)("sha256").update(fs5.readFileSync(path5.join(dir, relPath))).digest("hex");
|
|
4301
5855
|
}
|
|
4302
5856
|
return out;
|
|
4303
5857
|
}
|
|
@@ -4343,7 +5897,7 @@ function buildFileManifest(dir) {
|
|
|
4343
5897
|
path: relPath,
|
|
4344
5898
|
isDirectory: false,
|
|
4345
5899
|
size: payload.length,
|
|
4346
|
-
sha256: (0,
|
|
5900
|
+
sha256: (0, import_node_crypto6.createHash)("sha256").update(payload).digest("hex")
|
|
4347
5901
|
};
|
|
4348
5902
|
});
|
|
4349
5903
|
}
|
|
@@ -4542,11 +6096,11 @@ async function createRef(slug, name, kind, versionId, options = {}) {
|
|
|
4542
6096
|
...versionId ? { versionId } : {}
|
|
4543
6097
|
});
|
|
4544
6098
|
}
|
|
4545
|
-
var
|
|
6099
|
+
var import_node_crypto6, import_node_zlib2, fs5, path5, DEFAULT_BRANCH, META_RELPATH, FILE_MODE, MINTED_SUFFIX, PushSlugConflict, sha256b64, DetachedPushError;
|
|
4546
6100
|
var init_hub = __esm({
|
|
4547
6101
|
"src/worlds/hub.ts"() {
|
|
4548
6102
|
"use strict";
|
|
4549
|
-
|
|
6103
|
+
import_node_crypto6 = require("crypto");
|
|
4550
6104
|
import_node_zlib2 = require("zlib");
|
|
4551
6105
|
fs5 = __toESM(require("fs"));
|
|
4552
6106
|
path5 = __toESM(require("path"));
|
|
@@ -4572,7 +6126,7 @@ var init_hub = __esm({
|
|
|
4572
6126
|
tracked;
|
|
4573
6127
|
declared;
|
|
4574
6128
|
};
|
|
4575
|
-
sha256b64 = (data) => (0,
|
|
6129
|
+
sha256b64 = (data) => (0, import_node_crypto6.createHash)("sha256").update(data).digest("base64");
|
|
4576
6130
|
DetachedPushError = class extends Error {
|
|
4577
6131
|
constructor(dir, tag) {
|
|
4578
6132
|
super(
|
|
@@ -5216,11 +6770,11 @@ function applyTransforms(value, chain) {
|
|
|
5216
6770
|
for (const step of steps) out = step(out);
|
|
5217
6771
|
return out;
|
|
5218
6772
|
}
|
|
5219
|
-
var
|
|
6773
|
+
var import_node_crypto7, WHITESPACE, WHITESPACE_EDGES, WHITESPACE_RUN, NOT_DIGIT, STRIP_PREFIX, trim, emailLocalPart, emailDomain, stripPrefix, hex, SIMPLE, TRANSFORMS, text;
|
|
5220
6774
|
var init_transforms = __esm({
|
|
5221
6775
|
"src/worlds/transforms.ts"() {
|
|
5222
6776
|
"use strict";
|
|
5223
|
-
|
|
6777
|
+
import_node_crypto7 = require("crypto");
|
|
5224
6778
|
init_json();
|
|
5225
6779
|
WHITESPACE = " \n\r\f\v";
|
|
5226
6780
|
WHITESPACE_EDGES = new RegExp(`^[${WHITESPACE}]+|[${WHITESPACE}]+$`, "g");
|
|
@@ -5237,7 +6791,7 @@ var init_transforms = __esm({
|
|
|
5237
6791
|
return at === -1 ? "" : value.slice(at + 1).toLowerCase();
|
|
5238
6792
|
};
|
|
5239
6793
|
stripPrefix = (prefix) => (value) => value.startsWith(prefix) ? value.slice(prefix.length) : value;
|
|
5240
|
-
hex = (algorithm, value) => (0,
|
|
6794
|
+
hex = (algorithm, value) => (0, import_node_crypto7.createHash)(algorithm).update(value, "utf8").digest("hex");
|
|
5241
6795
|
SIMPLE = {
|
|
5242
6796
|
lower: (value) => value.toLowerCase(),
|
|
5243
6797
|
upper: (value) => value.toUpperCase(),
|
|
@@ -5269,7 +6823,7 @@ function pyText(value) {
|
|
|
5269
6823
|
return pyFloatRepr(value);
|
|
5270
6824
|
}
|
|
5271
6825
|
function hashForm(slug, plaintext) {
|
|
5272
|
-
return "sha256:" + (0,
|
|
6826
|
+
return "sha256:" + (0, import_node_crypto8.createHash)("sha256").update(`${slug}:${pyText(plaintext)}`, "utf8").digest("hex");
|
|
5273
6827
|
}
|
|
5274
6828
|
function preserveForm(slug, plaintext) {
|
|
5275
6829
|
const kind = typeof plaintext === "string" ? "str" : isInt(plaintext) ? "int" : "float";
|
|
@@ -5278,12 +6832,12 @@ function preserveForm(slug, plaintext) {
|
|
|
5278
6832
|
}
|
|
5279
6833
|
function shapeText(slug, text2, kind) {
|
|
5280
6834
|
const seed = Buffer.from(`${slug}:${text2}`, "utf8");
|
|
5281
|
-
let digest = (0,
|
|
6835
|
+
let digest = (0, import_node_crypto8.createHash)("sha256").update(seed).digest();
|
|
5282
6836
|
let cursor = 0;
|
|
5283
6837
|
const out = [];
|
|
5284
6838
|
for (const char of text2) {
|
|
5285
6839
|
if (cursor === digest.length) {
|
|
5286
|
-
digest = (0,
|
|
6840
|
+
digest = (0, import_node_crypto8.createHash)("sha256").update(Buffer.concat([digest, seed])).digest();
|
|
5287
6841
|
cursor = 0;
|
|
5288
6842
|
}
|
|
5289
6843
|
const byte = digest[cursor];
|
|
@@ -5320,11 +6874,11 @@ function storedForms(world, field2, plaintext, transform) {
|
|
|
5320
6874
|
if (policy !== null) return [roundForm(plaintext, world.redact.round[field2])];
|
|
5321
6875
|
return [plaintext];
|
|
5322
6876
|
}
|
|
5323
|
-
var
|
|
6877
|
+
var import_node_crypto8, isInt;
|
|
5324
6878
|
var init_redaction = __esm({
|
|
5325
6879
|
"src/worlds/redaction.ts"() {
|
|
5326
6880
|
"use strict";
|
|
5327
|
-
|
|
6881
|
+
import_node_crypto8 = require("crypto");
|
|
5328
6882
|
init_json();
|
|
5329
6883
|
init_transforms();
|
|
5330
6884
|
isInt = (value) => typeof value === "number" && Number.isInteger(value);
|
|
@@ -6193,7 +7747,7 @@ function uploadHeadersFor(gz) {
|
|
|
6193
7747
|
return {
|
|
6194
7748
|
"content-type": "application/gzip",
|
|
6195
7749
|
"content-length": String(gz.length),
|
|
6196
|
-
"x-amz-checksum-sha256": (0,
|
|
7750
|
+
"x-amz-checksum-sha256": (0, import_node_crypto9.createHash)("sha256").update(gz).digest("base64")
|
|
6197
7751
|
};
|
|
6198
7752
|
}
|
|
6199
7753
|
async function forEachLimited(items, limit, fn) {
|
|
@@ -6239,11 +7793,11 @@ function phaseLine(status) {
|
|
|
6239
7793
|
const phase = status.progress?.phase;
|
|
6240
7794
|
return phase ? `${status.state} (${phase})` : status.state;
|
|
6241
7795
|
}
|
|
6242
|
-
var
|
|
7796
|
+
var import_node_crypto9, fs11, TERMINAL_STATES, sleepMs, WorldDataApi;
|
|
6243
7797
|
var init_batches = __esm({
|
|
6244
7798
|
"src/cli/platform/worldData/batches.ts"() {
|
|
6245
7799
|
"use strict";
|
|
6246
|
-
|
|
7800
|
+
import_node_crypto9 = require("crypto");
|
|
6247
7801
|
fs11 = __toESM(require("fs"));
|
|
6248
7802
|
init_config();
|
|
6249
7803
|
init_router();
|
|
@@ -6437,12 +7991,12 @@ function finishChunk(ordinal, raw, rows, entity, firstRow = 0) {
|
|
|
6437
7991
|
const gz = gzipDeterministic(raw, { name: chunkName(ordinal) });
|
|
6438
7992
|
return {
|
|
6439
7993
|
ordinal,
|
|
6440
|
-
digest: (0,
|
|
7994
|
+
digest: (0, import_node_crypto10.createHash)("sha256").update(gz).digest("hex"),
|
|
6441
7995
|
bytes: gz.length,
|
|
6442
7996
|
rows,
|
|
6443
7997
|
entity,
|
|
6444
7998
|
rawBytes: raw.length,
|
|
6445
|
-
contentSha256: (0,
|
|
7999
|
+
contentSha256: (0, import_node_crypto10.createHash)("sha256").update(raw).digest("hex"),
|
|
6446
8000
|
firstRow,
|
|
6447
8001
|
gz
|
|
6448
8002
|
};
|
|
@@ -6482,11 +8036,11 @@ function crc32(data) {
|
|
|
6482
8036
|
crc = table[(crc ^ data[i]) & 255] ^ crc >>> 8;
|
|
6483
8037
|
return (crc ^ 4294967295) >>> 0;
|
|
6484
8038
|
}
|
|
6485
|
-
var
|
|
8039
|
+
var import_node_crypto10, import_node_zlib3, DEFAULT_CHUNK_BYTES, GZIP_LEVEL, chunkName, table;
|
|
6486
8040
|
var init_chunker = __esm({
|
|
6487
8041
|
"src/cli/platform/worldData/chunker.ts"() {
|
|
6488
8042
|
"use strict";
|
|
6489
|
-
|
|
8043
|
+
import_node_crypto10 = require("crypto");
|
|
6490
8044
|
import_node_zlib3 = require("zlib");
|
|
6491
8045
|
init_json();
|
|
6492
8046
|
DEFAULT_CHUNK_BYTES = 64 * 1024 * 1024;
|
|
@@ -6781,7 +8335,7 @@ var init_ingest = __esm({
|
|
|
6781
8335
|
});
|
|
6782
8336
|
|
|
6783
8337
|
// src/worlds/editSessions.ts
|
|
6784
|
-
var WORLDS, WorldEditClient;
|
|
8338
|
+
var WORLDS, WorldEditClient, TASK_EDITS, TaskEditClient;
|
|
6785
8339
|
var init_editSessions = __esm({
|
|
6786
8340
|
"src/worlds/editSessions.ts"() {
|
|
6787
8341
|
"use strict";
|
|
@@ -6813,6 +8367,22 @@ var init_editSessions = __esm({
|
|
|
6813
8367
|
return apiRequest(this.options, "POST", `${WORLDS}/${encodeURIComponent(slug)}/edits/rollback`, input);
|
|
6814
8368
|
}
|
|
6815
8369
|
};
|
|
8370
|
+
TASK_EDITS = "/api/public/world-task-edits";
|
|
8371
|
+
TaskEditClient = class {
|
|
8372
|
+
constructor(options = {}) {
|
|
8373
|
+
this.options = options;
|
|
8374
|
+
}
|
|
8375
|
+
options;
|
|
8376
|
+
status(task) {
|
|
8377
|
+
return apiRequest(this.options, "POST", `${TASK_EDITS}/status`, { task });
|
|
8378
|
+
}
|
|
8379
|
+
close(task, input = {}) {
|
|
8380
|
+
return apiRequest(this.options, "POST", `${TASK_EDITS}/close`, { task, ...input });
|
|
8381
|
+
}
|
|
8382
|
+
rollback(task, input) {
|
|
8383
|
+
return apiRequest(this.options, "POST", `${TASK_EDITS}/rollback`, { task, ...input });
|
|
8384
|
+
}
|
|
8385
|
+
};
|
|
6816
8386
|
}
|
|
6817
8387
|
});
|
|
6818
8388
|
|
|
@@ -6908,6 +8478,10 @@ var init_dryRun = __esm({
|
|
|
6908
8478
|
// src/worlds/index.ts
|
|
6909
8479
|
var worlds_exports = {};
|
|
6910
8480
|
__export(worlds_exports, {
|
|
8481
|
+
ACTION_NAMES: () => ACTION_NAMES,
|
|
8482
|
+
ActionTracer: () => ActionTracer,
|
|
8483
|
+
AnthropicComputer: () => AnthropicComputer,
|
|
8484
|
+
AnthropicComputer20251124: () => AnthropicComputer20251124,
|
|
6911
8485
|
ApiError: () => ApiError,
|
|
6912
8486
|
BROWSER_GONE_PATTERNS: () => BROWSER_GONE_PATTERNS,
|
|
6913
8487
|
BROWSER_TIERS: () => BROWSER_TIERS,
|
|
@@ -6919,11 +8493,13 @@ __export(worlds_exports, {
|
|
|
6919
8493
|
CALL_BODY_LIMIT_LABEL: () => CALL_BODY_LIMIT_LABEL,
|
|
6920
8494
|
COMPUTER_USE_SPECS: () => COMPUTER_USE_SPECS,
|
|
6921
8495
|
CheckoutProvenance: () => CheckoutProvenance,
|
|
8496
|
+
ComputerAction: () => ComputerAction,
|
|
6922
8497
|
DEFAULT_BRANCH: () => DEFAULT_BRANCH,
|
|
6923
8498
|
DEFAULT_VIEWPORT: () => DEFAULT_VIEWPORT,
|
|
6924
8499
|
DRY_RUN_AGENT: () => DRY_RUN_AGENT,
|
|
6925
8500
|
DRY_RUN_KIND: () => DRY_RUN_KIND,
|
|
6926
8501
|
DetachedPushError: () => DetachedPushError,
|
|
8502
|
+
Display: () => Display,
|
|
6927
8503
|
DryRunOutcome: () => DryRunOutcome,
|
|
6928
8504
|
EVENT_BATCH_SIZE: () => EVENT_BATCH_SIZE,
|
|
6929
8505
|
EVENT_FLUSH_INTERVAL_MS: () => EVENT_FLUSH_INTERVAL_MS,
|
|
@@ -6933,19 +8509,30 @@ __export(worlds_exports, {
|
|
|
6933
8509
|
GatewayEvalsClient: () => GatewayEvalsClient,
|
|
6934
8510
|
HostedDryRunClient: () => HostedDryRunClient,
|
|
6935
8511
|
IDLE_WARNING_MINUTES: () => IDLE_WARNING_MINUTES,
|
|
8512
|
+
KEY_NAMES: () => KEY_NAMES,
|
|
8513
|
+
KeyChord: () => KeyChord,
|
|
8514
|
+
NOT_EXECUTED: () => NOT_EXECUTED,
|
|
6936
8515
|
NO_GRADER_REASON: () => NO_GRADER_REASON,
|
|
8516
|
+
NativeComputer: () => NativeComputer,
|
|
8517
|
+
OpenAIComputer: () => OpenAIComputer,
|
|
8518
|
+
OpenAIPreviewComputer: () => OpenAIPreviewComputer,
|
|
6937
8519
|
PLATFORM_TIMEOUT_DEFAULT_MS: () => PLATFORM_TIMEOUT_DEFAULT_MS,
|
|
6938
8520
|
PLATFORM_TIMEOUT_ENV: () => PLATFORM_TIMEOUT_ENV,
|
|
8521
|
+
PendingSafetyChecks: () => PendingSafetyChecks,
|
|
6939
8522
|
PlatformTransport: () => PlatformTransport,
|
|
6940
8523
|
PushSlugConflict: () => PushSlugConflict,
|
|
6941
8524
|
RECOVER_BUDGET_MS: () => RECOVER_BUDGET_MS,
|
|
6942
8525
|
SANDBOX_REQUEST_TIMEOUT_MS: () => SANDBOX_REQUEST_TIMEOUT_MS,
|
|
8526
|
+
SECRET_KEY: () => SECRET_KEY,
|
|
6943
8527
|
SESSION_STATES: () => SESSION_STATES,
|
|
8528
|
+
SPAN_PREFIX: () => SPAN_PREFIX,
|
|
6944
8529
|
STATUS_WAIT_CAP_SECONDS: () => STATUS_WAIT_CAP_SECONDS,
|
|
6945
8530
|
STRIP_PREFIX: () => STRIP_PREFIX,
|
|
6946
8531
|
SURFACE_KINDS: () => SURFACE_KINDS,
|
|
8532
|
+
Screen: () => Screen,
|
|
6947
8533
|
SecretScrubber: () => SecretScrubber,
|
|
6948
8534
|
TRANSFORMS: () => TRANSFORMS,
|
|
8535
|
+
TaskEditClient: () => TaskEditClient,
|
|
6949
8536
|
TaskRun: () => TaskRun,
|
|
6950
8537
|
TaskSessions: () => TaskSessions,
|
|
6951
8538
|
TransportCause: () => TransportCause,
|
|
@@ -7018,6 +8605,7 @@ __export(worlds_exports, {
|
|
|
7018
8605
|
parseTransform: () => parseTransform,
|
|
7019
8606
|
parseWorldTaskRefs: () => parseWorldTaskRefs,
|
|
7020
8607
|
platformTimeoutMs: () => platformTimeoutMs,
|
|
8608
|
+
playwrightKey: () => playwrightKey,
|
|
7021
8609
|
preserveForm: () => preserveForm,
|
|
7022
8610
|
propose: () => propose,
|
|
7023
8611
|
pull: () => pull,
|
|
@@ -7027,6 +8615,7 @@ __export(worlds_exports, {
|
|
|
7027
8615
|
pyText: () => pyText,
|
|
7028
8616
|
queryRows: () => queryRows,
|
|
7029
8617
|
queryRowsSearch: () => queryRowsSearch,
|
|
8618
|
+
readField: () => readField,
|
|
7030
8619
|
readLocalMeta: () => readLocalMeta,
|
|
7031
8620
|
readToolCallRecords: () => readToolCallRecords,
|
|
7032
8621
|
rebaseConflicts: () => rebaseConflicts,
|
|
@@ -7276,7 +8865,7 @@ var init_worlds = __esm({
|
|
|
7276
8865
|
"use strict";
|
|
7277
8866
|
init_transport();
|
|
7278
8867
|
init_transport();
|
|
7279
|
-
|
|
8868
|
+
init_session2();
|
|
7280
8869
|
init_sessionList();
|
|
7281
8870
|
init_sessionContract();
|
|
7282
8871
|
init_taskRef();
|
|
@@ -7288,6 +8877,7 @@ var init_worlds = __esm({
|
|
|
7288
8877
|
init_evals();
|
|
7289
8878
|
init_browser();
|
|
7290
8879
|
init_browserReconnect();
|
|
8880
|
+
init_nativeComputer();
|
|
7291
8881
|
init_hub();
|
|
7292
8882
|
init_validate();
|
|
7293
8883
|
init_describe();
|
|
@@ -7354,7 +8944,7 @@ var init_worlds = __esm({
|
|
|
7354
8944
|
* worlds/session.ts.
|
|
7355
8945
|
*/
|
|
7356
8946
|
async open(task, opts = {}) {
|
|
7357
|
-
const { openSession: openSession2 } = await Promise.resolve().then(() => (
|
|
8947
|
+
const { openSession: openSession2 } = await Promise.resolve().then(() => (init_session2(), session_exports2));
|
|
7358
8948
|
return openSession2(this.slug, {
|
|
7359
8949
|
task,
|
|
7360
8950
|
versionId: this.version.versionId,
|
|
@@ -7390,7 +8980,11 @@ var init_worlds = __esm({
|
|
|
7390
8980
|
// src/index.ts
|
|
7391
8981
|
var src_exports = {};
|
|
7392
8982
|
__export(src_exports, {
|
|
8983
|
+
ACTION_NAMES: () => ACTION_NAMES,
|
|
7393
8984
|
AGENT_ID_KEY: () => AGENT_ID_KEY,
|
|
8985
|
+
ActionTracer: () => ActionTracer,
|
|
8986
|
+
AnthropicComputer: () => AnthropicComputer,
|
|
8987
|
+
AnthropicComputer20251124: () => AnthropicComputer20251124,
|
|
7394
8988
|
ApiError: () => ApiError,
|
|
7395
8989
|
BROWSER_GONE_PATTERNS: () => BROWSER_GONE_PATTERNS,
|
|
7396
8990
|
BROWSER_TIERS: () => BROWSER_TIERS,
|
|
@@ -7402,12 +8996,14 @@ __export(src_exports, {
|
|
|
7402
8996
|
CALL_BODY_LIMIT_LABEL: () => CALL_BODY_LIMIT_LABEL,
|
|
7403
8997
|
COMPUTER_USE_SPECS: () => COMPUTER_USE_SPECS,
|
|
7404
8998
|
CheckoutProvenance: () => CheckoutProvenance,
|
|
8999
|
+
ComputerAction: () => ComputerAction,
|
|
7405
9000
|
DEFAULT_BRANCH: () => DEFAULT_BRANCH,
|
|
7406
9001
|
DEFAULT_TIMEOUT_SECONDS: () => DEFAULT_TIMEOUT_SECONDS,
|
|
7407
9002
|
DEFAULT_VIEWPORT: () => DEFAULT_VIEWPORT,
|
|
7408
9003
|
DRY_RUN_AGENT: () => DRY_RUN_AGENT,
|
|
7409
9004
|
DRY_RUN_KIND: () => DRY_RUN_KIND,
|
|
7410
9005
|
DetachedPushError: () => DetachedPushError,
|
|
9006
|
+
Display: () => Display,
|
|
7411
9007
|
DriftError: () => DriftError,
|
|
7412
9008
|
DryRunOutcome: () => DryRunOutcome,
|
|
7413
9009
|
ENV_GATEWAY_HOST: () => ENV_GATEWAY_HOST,
|
|
@@ -7435,9 +9031,16 @@ __export(src_exports, {
|
|
|
7435
9031
|
GatewayToolBlockedError: () => GatewayToolBlockedError,
|
|
7436
9032
|
HostedDryRunClient: () => HostedDryRunClient,
|
|
7437
9033
|
IDLE_WARNING_MINUTES: () => IDLE_WARNING_MINUTES,
|
|
9034
|
+
KEY_NAMES: () => KEY_NAMES,
|
|
9035
|
+
KeyChord: () => KeyChord,
|
|
9036
|
+
NOT_EXECUTED: () => NOT_EXECUTED,
|
|
7438
9037
|
NO_GRADER_REASON: () => NO_GRADER_REASON,
|
|
9038
|
+
NativeComputer: () => NativeComputer,
|
|
9039
|
+
OpenAIComputer: () => OpenAIComputer,
|
|
9040
|
+
OpenAIPreviewComputer: () => OpenAIPreviewComputer,
|
|
7439
9041
|
PLATFORM_TIMEOUT_DEFAULT_MS: () => PLATFORM_TIMEOUT_DEFAULT_MS,
|
|
7440
9042
|
PLATFORM_TIMEOUT_ENV: () => PLATFORM_TIMEOUT_ENV,
|
|
9043
|
+
PendingSafetyChecks: () => PendingSafetyChecks,
|
|
7441
9044
|
Persona: () => Persona,
|
|
7442
9045
|
PersonaError: () => PersonaError,
|
|
7443
9046
|
PersonasClient: () => PersonasClient,
|
|
@@ -7452,7 +9055,9 @@ __export(src_exports, {
|
|
|
7452
9055
|
ReplaySuite: () => ReplaySuite,
|
|
7453
9056
|
ReplayTask: () => ReplayTask,
|
|
7454
9057
|
SANDBOX_REQUEST_TIMEOUT_MS: () => SANDBOX_REQUEST_TIMEOUT_MS,
|
|
9058
|
+
SECRET_KEY: () => SECRET_KEY,
|
|
7455
9059
|
SESSION_STATES: () => SESSION_STATES,
|
|
9060
|
+
SPAN_PREFIX: () => SPAN_PREFIX,
|
|
7456
9061
|
STATUS_WAIT_CAP_SECONDS: () => STATUS_WAIT_CAP_SECONDS,
|
|
7457
9062
|
STRIP_PREFIX: () => STRIP_PREFIX,
|
|
7458
9063
|
SUCCESS_METRIC_NAME_KEY: () => SUCCESS_METRIC_NAME_KEY,
|
|
@@ -7460,12 +9065,14 @@ __export(src_exports, {
|
|
|
7460
9065
|
SURFACE_KINDS: () => SURFACE_KINDS,
|
|
7461
9066
|
ScoreError: () => ScoreError,
|
|
7462
9067
|
ScoresClient: () => ScoresClient,
|
|
9068
|
+
Screen: () => Screen,
|
|
7463
9069
|
SecretScrubber: () => SecretScrubber,
|
|
7464
9070
|
SessionLoadError: () => SessionLoadError,
|
|
7465
9071
|
SessionRecording: () => SessionRecording,
|
|
7466
9072
|
SessionTrace: () => SessionTrace,
|
|
7467
9073
|
StubMissError: () => StubMissError,
|
|
7468
9074
|
TRANSFORMS: () => TRANSFORMS,
|
|
9075
|
+
TaskEditClient: () => TaskEditClient,
|
|
7469
9076
|
TaskRun: () => TaskRun,
|
|
7470
9077
|
TaskSessions: () => TaskSessions,
|
|
7471
9078
|
ToolStubRegistry: () => ToolStubRegistry,
|
|
@@ -7567,6 +9174,7 @@ __export(src_exports, {
|
|
|
7567
9174
|
parseWorldTaskRefs: () => parseWorldTaskRefs,
|
|
7568
9175
|
personas: () => personas,
|
|
7569
9176
|
platformTimeoutMs: () => platformTimeoutMs,
|
|
9177
|
+
playwrightKey: () => playwrightKey,
|
|
7570
9178
|
preserveForm: () => preserveForm,
|
|
7571
9179
|
propose: () => propose,
|
|
7572
9180
|
pull: () => pull,
|
|
@@ -7576,6 +9184,7 @@ __export(src_exports, {
|
|
|
7576
9184
|
pyText: () => pyText,
|
|
7577
9185
|
queryRows: () => queryRows,
|
|
7578
9186
|
queryRowsSearch: () => queryRowsSearch,
|
|
9187
|
+
readField: () => readField,
|
|
7579
9188
|
readLocalMeta: () => readLocalMeta,
|
|
7580
9189
|
readToolCallRecords: () => readToolCallRecords,
|
|
7581
9190
|
rebaseConflicts: () => rebaseConflicts,
|
|
@@ -10022,7 +11631,7 @@ var gateway = {
|
|
|
10022
11631
|
init_users();
|
|
10023
11632
|
init_scores();
|
|
10024
11633
|
init_worlds();
|
|
10025
|
-
|
|
11634
|
+
init_session2();
|
|
10026
11635
|
|
|
10027
11636
|
// src/files/index.ts
|
|
10028
11637
|
var files_exports = {};
|
|
@@ -10048,7 +11657,7 @@ __export(files_exports, {
|
|
|
10048
11657
|
uploadBytes: () => uploadBytes,
|
|
10049
11658
|
uploadFile: () => uploadFile
|
|
10050
11659
|
});
|
|
10051
|
-
var
|
|
11660
|
+
var import_node_crypto11 = require("crypto");
|
|
10052
11661
|
var fs13 = __toESM(require("fs"));
|
|
10053
11662
|
var path12 = __toESM(require("path"));
|
|
10054
11663
|
var import_node_stream = require("stream");
|
|
@@ -10114,7 +11723,7 @@ async function confirmUpload(options = {}, fileId, ok = true) {
|
|
|
10114
11723
|
return apiRequest(options, "POST", `${BASE}/confirm`, { fileId, ok });
|
|
10115
11724
|
}
|
|
10116
11725
|
async function sha256Base64(localPath) {
|
|
10117
|
-
const hash = (0,
|
|
11726
|
+
const hash = (0, import_node_crypto11.createHash)("sha256");
|
|
10118
11727
|
for await (const chunk of fs13.createReadStream(localPath)) hash.update(chunk);
|
|
10119
11728
|
return hash.digest("base64");
|
|
10120
11729
|
}
|
|
@@ -10199,7 +11808,7 @@ async function uploadBytes(options = {}, bytes, targetPath, upload = {}) {
|
|
|
10199
11808
|
if (!bytes.length) throw new Error("nothing to upload: the content is empty");
|
|
10200
11809
|
const target = drivePath(targetPath);
|
|
10201
11810
|
const contentType = upload.contentType ?? contentTypeFor(target);
|
|
10202
|
-
const sha2562 = (0,
|
|
11811
|
+
const sha2562 = (0, import_node_crypto11.createHash)("sha256").update(bytes).digest("base64");
|
|
10203
11812
|
const granted = await requestUpload(options, { path: target, contentLength: bytes.length, contentType, sha256: sha2562, ...upload.overwrite ? { overwrite: true } : {} });
|
|
10204
11813
|
try {
|
|
10205
11814
|
await putPresigned(granted.uploadUrl, new Uint8Array(bytes), { contentType, contentLength: bytes.length, sha256: sha2562 });
|
|
@@ -10452,10 +12061,10 @@ function swapValue(text2, needle, replacement) {
|
|
|
10452
12061
|
}
|
|
10453
12062
|
|
|
10454
12063
|
// src/hooks/standInDigits.ts
|
|
10455
|
-
var
|
|
12064
|
+
var import_node_crypto12 = require("crypto");
|
|
10456
12065
|
function standInDigits(realDigits, identityName) {
|
|
10457
12066
|
if (!realDigits) return "";
|
|
10458
|
-
const digest = (0,
|
|
12067
|
+
const digest = (0, import_node_crypto12.createHash)("sha256").update(`${identityName}:${realDigits}`).digest("hex");
|
|
10459
12068
|
let digits = "";
|
|
10460
12069
|
for (let i = 0; i < realDigits.length; i++)
|
|
10461
12070
|
digits += String(parseInt(digest[i % digest.length], 16) % 10);
|
|
@@ -10489,7 +12098,7 @@ var DeclaredStandIn = class _DeclaredStandIn {
|
|
|
10489
12098
|
};
|
|
10490
12099
|
|
|
10491
12100
|
// src/hooks/alias.ts
|
|
10492
|
-
var
|
|
12101
|
+
var import_node_crypto13 = require("crypto");
|
|
10493
12102
|
var GIVEN = [
|
|
10494
12103
|
"John",
|
|
10495
12104
|
"Mary",
|
|
@@ -10680,7 +12289,7 @@ function findKind(kind, text2) {
|
|
|
10680
12289
|
return out;
|
|
10681
12290
|
}
|
|
10682
12291
|
function newRunKey() {
|
|
10683
|
-
return (0,
|
|
12292
|
+
return (0, import_node_crypto13.randomBytes)(32).toString("hex");
|
|
10684
12293
|
}
|
|
10685
12294
|
function canonical(kind, value) {
|
|
10686
12295
|
const text2 = String(value).normalize("NFKC").trim();
|
|
@@ -10737,7 +12346,7 @@ function explodeIp(text2) {
|
|
|
10737
12346
|
return groups.map((g) => g.padStart(4, "0")).join(":") + zone;
|
|
10738
12347
|
}
|
|
10739
12348
|
function index(runKey, kind, value, salt = "") {
|
|
10740
|
-
const digest = (0,
|
|
12349
|
+
const digest = (0, import_node_crypto13.createHmac)("sha256", Buffer.from(runKey, "hex")).update(`${kind}:${value}:${salt}`, "utf8").digest();
|
|
10741
12350
|
return digest.readBigUInt64BE(0);
|
|
10742
12351
|
}
|
|
10743
12352
|
var pick = (pool, n) => pool[Number(n % BigInt(pool.length))];
|
|
@@ -10761,7 +12370,7 @@ function nameParts(name) {
|
|
|
10761
12370
|
function format(template, parts2) {
|
|
10762
12371
|
return template.replace(/\{(\w+)\}/g, (_, key2) => parts2[key2] ?? "").trim();
|
|
10763
12372
|
}
|
|
10764
|
-
var
|
|
12373
|
+
var pair2 = (real, fake, template) => [
|
|
10765
12374
|
format(template, real),
|
|
10766
12375
|
format(template, fake)
|
|
10767
12376
|
];
|
|
@@ -10821,7 +12430,7 @@ function namePairs(real, fake) {
|
|
|
10821
12430
|
const out = [[real, fake]];
|
|
10822
12431
|
if (realParts.given && realParts.surname) {
|
|
10823
12432
|
for (const template of NAME_FORMS) {
|
|
10824
|
-
const p =
|
|
12433
|
+
const p = pair2(realParts, fakeParts, template);
|
|
10825
12434
|
if (p[0].length > 2 && !p[0].includes("{")) out.push(p);
|
|
10826
12435
|
}
|
|
10827
12436
|
}
|
|
@@ -10859,7 +12468,7 @@ function emailPairs(real, fake) {
|
|
|
10859
12468
|
};
|
|
10860
12469
|
const out = [[real, fake]];
|
|
10861
12470
|
for (const template of EMAIL_FORMS) {
|
|
10862
|
-
const p =
|
|
12471
|
+
const p = pair2(realParts, fakeParts, template);
|
|
10863
12472
|
if (p[0].length > 2) out.push(p);
|
|
10864
12473
|
}
|
|
10865
12474
|
return dedupe(out);
|
|
@@ -11271,7 +12880,7 @@ var AliasMap = class _AliasMap {
|
|
|
11271
12880
|
const existing = this.aliases.get(key2);
|
|
11272
12881
|
if (existing) return existing.display;
|
|
11273
12882
|
if (this.aliasDigests.has(digest.toLowerCase())) return digest;
|
|
11274
|
-
const standIn = "sha256:" + (0,
|
|
12883
|
+
const standIn = "sha256:" + (0, import_node_crypto13.createHmac)("sha256", Buffer.from(this.runKey, "hex")).update(digest, "utf8").digest("hex");
|
|
11275
12884
|
this.aliasDigests.add(standIn.toLowerCase());
|
|
11276
12885
|
const alias = {
|
|
11277
12886
|
kind: "digest",
|
|
@@ -11310,9 +12919,9 @@ var AliasMap = class _AliasMap {
|
|
|
11310
12919
|
});
|
|
11311
12920
|
if (alias.role === "private") {
|
|
11312
12921
|
for (const slug of this.slugs) {
|
|
11313
|
-
const standIn = "sha256:" + (0,
|
|
12922
|
+
const standIn = "sha256:" + (0, import_node_crypto13.createHash)("sha256").update(`${slug}:${canonical(alias.kind, alias.display)}`, "utf8").digest("hex");
|
|
11314
12923
|
alias.variants.push([
|
|
11315
|
-
"sha256:" + (0,
|
|
12924
|
+
"sha256:" + (0, import_node_crypto13.createHash)("sha256").update(`${slug}:${alias.canonical}`, "utf8").digest("hex"),
|
|
11316
12925
|
standIn
|
|
11317
12926
|
]);
|
|
11318
12927
|
this.aliasDigests.add(standIn.toLowerCase());
|
|
@@ -12127,7 +13736,7 @@ function inputSchema(shorthand, position) {
|
|
|
12127
13736
|
`${position}.input: expected a table of field = "type"`
|
|
12128
13737
|
);
|
|
12129
13738
|
const properties = {};
|
|
12130
|
-
const
|
|
13739
|
+
const required2 = [];
|
|
12131
13740
|
for (const [name, raw] of Object.entries(shorthand)) {
|
|
12132
13741
|
if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(name))
|
|
12133
13742
|
throw new HookConfigError(
|
|
@@ -12161,9 +13770,9 @@ function inputSchema(shorthand, position) {
|
|
|
12161
13770
|
`${position}.input.${name}: expected "type" or a schema table`
|
|
12162
13771
|
);
|
|
12163
13772
|
properties[name] = schema;
|
|
12164
|
-
if (!optional)
|
|
13773
|
+
if (!optional) required2.push(name);
|
|
12165
13774
|
}
|
|
12166
|
-
return { type: "object", properties, required };
|
|
13775
|
+
return { type: "object", properties, required: required2 };
|
|
12167
13776
|
}
|
|
12168
13777
|
function placeholders(value) {
|
|
12169
13778
|
if (typeof value === "string")
|
|
@@ -14308,7 +15917,7 @@ var RedactionAudit = class _RedactionAudit {
|
|
|
14308
15917
|
};
|
|
14309
15918
|
|
|
14310
15919
|
// src/hooks/run.ts
|
|
14311
|
-
var
|
|
15920
|
+
var import_node_crypto14 = require("crypto");
|
|
14312
15921
|
var fs17 = __toESM(require("fs"));
|
|
14313
15922
|
var path15 = __toESM(require("path"));
|
|
14314
15923
|
var BLOCKING_EVENTS = [
|
|
@@ -14352,7 +15961,7 @@ var HookRun = class _HookRun {
|
|
|
14352
15961
|
source;
|
|
14353
15962
|
constructor(config, options) {
|
|
14354
15963
|
this.config = config;
|
|
14355
|
-
this.runId = options.runId ?? `run-${(0,
|
|
15964
|
+
this.runId = options.runId ?? `run-${(0, import_node_crypto14.randomBytes)(6).toString("hex")}`;
|
|
14356
15965
|
this.runKey = options.runKey ?? newRunKey();
|
|
14357
15966
|
this.alias = new AliasMap(this.runKey, options.slugs ?? config.aliasSlugs, {
|
|
14358
15967
|
publicLayerWins: config.aliasPublicLayerWins,
|
|
@@ -14987,11 +16596,20 @@ init_identity();
|
|
|
14987
16596
|
var tracing_exports = {};
|
|
14988
16597
|
__export(tracing_exports, {
|
|
14989
16598
|
IdentitySpanProcessor: () => IdentitySpanProcessor,
|
|
16599
|
+
MAX_MEDIA_BYTES: () => MAX_MEDIA_BYTES,
|
|
16600
|
+
MediaReference: () => MediaReference,
|
|
16601
|
+
MediaUploadError: () => MediaUploadError,
|
|
16602
|
+
MediaUploader: () => MediaUploader,
|
|
16603
|
+
SECRET_KEYS: () => SECRET_KEYS,
|
|
14990
16604
|
SESSION_ID_ATTRIBUTE: () => SESSION_ID_ATTRIBUTE,
|
|
16605
|
+
SecretRedactingSpanProcessor: () => SecretRedactingSpanProcessor,
|
|
14991
16606
|
SessionSpanProcessor: () => SessionSpanProcessor,
|
|
16607
|
+
SpanSecrets: () => SpanSecrets,
|
|
14992
16608
|
USER_ID_ATTRIBUTE: () => USER_ID_ATTRIBUTE,
|
|
16609
|
+
WORLD_SESSION_ID_ATTRIBUTE: () => WORLD_SESSION_ID_ATTRIBUTE,
|
|
14993
16610
|
flush: () => flush,
|
|
14994
16611
|
getAmbientSessionId: () => getAmbientSessionId,
|
|
16612
|
+
getCurrentWorldSessionId: () => getCurrentWorldSessionId,
|
|
14995
16613
|
identify: () => identify,
|
|
14996
16614
|
init: () => init2,
|
|
14997
16615
|
initIsolated: () => initIsolated,
|
|
@@ -15004,11 +16622,13 @@ __export(tracing_exports, {
|
|
|
15004
16622
|
resetAmbientUser: () => resetAmbientUser,
|
|
15005
16623
|
resolveUserId: () => resolveUserId,
|
|
15006
16624
|
shutdown: () => shutdown2,
|
|
15007
|
-
withSession: () => withSession
|
|
16625
|
+
withSession: () => withSession,
|
|
16626
|
+
withWorldSession: () => withWorldSession
|
|
15008
16627
|
});
|
|
15009
16628
|
init_init();
|
|
15010
16629
|
init_identity();
|
|
15011
|
-
|
|
16630
|
+
init_session();
|
|
16631
|
+
init_secrets();
|
|
15012
16632
|
|
|
15013
16633
|
// src/tracing/observe.ts
|
|
15014
16634
|
var import_api3 = require("@opentelemetry/api");
|
|
@@ -15267,6 +16887,9 @@ async function* observeClaude(stream, options) {
|
|
|
15267
16887
|
}
|
|
15268
16888
|
}
|
|
15269
16889
|
|
|
16890
|
+
// src/tracing/index.ts
|
|
16891
|
+
init_media();
|
|
16892
|
+
|
|
15270
16893
|
// src/index.ts
|
|
15271
16894
|
var tracing = {
|
|
15272
16895
|
...tracing_exports,
|
|
@@ -15286,7 +16909,11 @@ var tracing = {
|
|
|
15286
16909
|
};
|
|
15287
16910
|
// Annotate the CommonJS export names for ESM import in node:
|
|
15288
16911
|
0 && (module.exports = {
|
|
16912
|
+
ACTION_NAMES,
|
|
15289
16913
|
AGENT_ID_KEY,
|
|
16914
|
+
ActionTracer,
|
|
16915
|
+
AnthropicComputer,
|
|
16916
|
+
AnthropicComputer20251124,
|
|
15290
16917
|
ApiError,
|
|
15291
16918
|
BROWSER_GONE_PATTERNS,
|
|
15292
16919
|
BROWSER_TIERS,
|
|
@@ -15298,12 +16925,14 @@ var tracing = {
|
|
|
15298
16925
|
CALL_BODY_LIMIT_LABEL,
|
|
15299
16926
|
COMPUTER_USE_SPECS,
|
|
15300
16927
|
CheckoutProvenance,
|
|
16928
|
+
ComputerAction,
|
|
15301
16929
|
DEFAULT_BRANCH,
|
|
15302
16930
|
DEFAULT_TIMEOUT_SECONDS,
|
|
15303
16931
|
DEFAULT_VIEWPORT,
|
|
15304
16932
|
DRY_RUN_AGENT,
|
|
15305
16933
|
DRY_RUN_KIND,
|
|
15306
16934
|
DetachedPushError,
|
|
16935
|
+
Display,
|
|
15307
16936
|
DriftError,
|
|
15308
16937
|
DryRunOutcome,
|
|
15309
16938
|
ENV_GATEWAY_HOST,
|
|
@@ -15331,9 +16960,16 @@ var tracing = {
|
|
|
15331
16960
|
GatewayToolBlockedError,
|
|
15332
16961
|
HostedDryRunClient,
|
|
15333
16962
|
IDLE_WARNING_MINUTES,
|
|
16963
|
+
KEY_NAMES,
|
|
16964
|
+
KeyChord,
|
|
16965
|
+
NOT_EXECUTED,
|
|
15334
16966
|
NO_GRADER_REASON,
|
|
16967
|
+
NativeComputer,
|
|
16968
|
+
OpenAIComputer,
|
|
16969
|
+
OpenAIPreviewComputer,
|
|
15335
16970
|
PLATFORM_TIMEOUT_DEFAULT_MS,
|
|
15336
16971
|
PLATFORM_TIMEOUT_ENV,
|
|
16972
|
+
PendingSafetyChecks,
|
|
15337
16973
|
Persona,
|
|
15338
16974
|
PersonaError,
|
|
15339
16975
|
PersonasClient,
|
|
@@ -15348,7 +16984,9 @@ var tracing = {
|
|
|
15348
16984
|
ReplaySuite,
|
|
15349
16985
|
ReplayTask,
|
|
15350
16986
|
SANDBOX_REQUEST_TIMEOUT_MS,
|
|
16987
|
+
SECRET_KEY,
|
|
15351
16988
|
SESSION_STATES,
|
|
16989
|
+
SPAN_PREFIX,
|
|
15352
16990
|
STATUS_WAIT_CAP_SECONDS,
|
|
15353
16991
|
STRIP_PREFIX,
|
|
15354
16992
|
SUCCESS_METRIC_NAME_KEY,
|
|
@@ -15356,12 +16994,14 @@ var tracing = {
|
|
|
15356
16994
|
SURFACE_KINDS,
|
|
15357
16995
|
ScoreError,
|
|
15358
16996
|
ScoresClient,
|
|
16997
|
+
Screen,
|
|
15359
16998
|
SecretScrubber,
|
|
15360
16999
|
SessionLoadError,
|
|
15361
17000
|
SessionRecording,
|
|
15362
17001
|
SessionTrace,
|
|
15363
17002
|
StubMissError,
|
|
15364
17003
|
TRANSFORMS,
|
|
17004
|
+
TaskEditClient,
|
|
15365
17005
|
TaskRun,
|
|
15366
17006
|
TaskSessions,
|
|
15367
17007
|
ToolStubRegistry,
|
|
@@ -15463,6 +17103,7 @@ var tracing = {
|
|
|
15463
17103
|
parseWorldTaskRefs,
|
|
15464
17104
|
personas,
|
|
15465
17105
|
platformTimeoutMs,
|
|
17106
|
+
playwrightKey,
|
|
15466
17107
|
preserveForm,
|
|
15467
17108
|
propose,
|
|
15468
17109
|
pull,
|
|
@@ -15472,6 +17113,7 @@ var tracing = {
|
|
|
15472
17113
|
pyText,
|
|
15473
17114
|
queryRows,
|
|
15474
17115
|
queryRowsSearch,
|
|
17116
|
+
readField,
|
|
15475
17117
|
readLocalMeta,
|
|
15476
17118
|
readToolCallRecords,
|
|
15477
17119
|
rebaseConflicts,
|