@withgateway/sdk 0.2.9 → 0.3.1
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/README.md +5 -1
- package/dist/cli.js +3812 -1158
- package/dist/cli.js.map +1 -1
- package/dist/cli.mjs +3796 -1142
- 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 +1358 -21
- package/dist/files/index.js.map +1 -1
- package/dist/files/index.mjs +1356 -13
- package/dist/files/index.mjs.map +1 -1
- package/dist/{index-BO2SNSgy.d.ts → index-CBqbB_0J.d.ts} +95 -46
- package/dist/{index-Cz8Q6Keo.d.mts → index-D-AMnAMa.d.mts} +95 -46
- package/dist/index.d.mts +4 -3
- package/dist/index.d.ts +4 -3
- package/dist/index.js +1942 -177
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1890 -146
- 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 +1355 -18
- package/dist/traces/index.js.map +1 -1
- package/dist/traces/index.mjs +1353 -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 +550 -30
- package/dist/tracing/index.js.map +1 -1
- package/dist/tracing/index.mjs +539 -29
- package/dist/tracing/index.mjs.map +1 -1
- package/dist/worlds/index.d.mts +648 -80
- package/dist/worlds/index.d.ts +648 -80
- package/dist/worlds/index.js +1875 -145
- package/dist/worlds/index.js.map +1 -1
- package/dist/worlds/index.mjs +1861 -131
- package/dist/worlds/index.mjs.map +1 -1
- package/package.json +1 -1
- package/runtime/gatewaysdk/environment/schema/api.py +43 -62
- package/runtime/gatewaysdk/environment/schema/cast.py +31 -4
- 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/platform.py +1 -7
- package/runtime/gatewaysdk/environment/schema/runtime.py +9 -9
- package/runtime/gatewaysdk/environment/schema/skills/connector-schema-authoring/SKILL.md +3 -3
- package/runtime/gatewaysdk/environment/schema/skills/world-data-ingestion/SKILL.md +2 -2
- package/runtime/gatewaysdk/environment/schema/skills/worlds-getting-started/SKILL.md +13 -13
- package/runtime/gatewaysdk/environment/schema/skills/worlds-getting-started/references/cli-mcp-map.md +2 -1
- package/runtime/gatewaysdk/environment/schema/tasks.py +25 -1
- package/skills/connector-schema-authoring/SKILL.md +3 -3
- package/skills/connector-schema-authoring/connector-worlds.md +12 -5
- package/skills/connector-schema-authoring/world-schema.md +8 -0
- package/skills/world-data-ingestion/SKILL.md +2 -2
- package/skills/worlds-getting-started/SKILL.md +13 -13
- package/skills/worlds-getting-started/references/cli-mcp-map.md +2 -1
package/dist/index.mjs
CHANGED
|
@@ -742,7 +742,7 @@ function withoutUiToken(url) {
|
|
|
742
742
|
const [beforeHash, hash] = splitHash(url);
|
|
743
743
|
const q = beforeHash.indexOf("?");
|
|
744
744
|
if (q < 0) return url;
|
|
745
|
-
const kept = beforeHash.slice(q + 1).split("&").filter((
|
|
745
|
+
const kept = beforeHash.slice(q + 1).split("&").filter((pair3) => pair3 !== "" && pair3.split("=")[0] !== UI_TOKEN_QUERY);
|
|
746
746
|
return beforeHash.slice(0, q) + (kept.length ? `?${kept.join("&")}` : "") + hash;
|
|
747
747
|
}
|
|
748
748
|
function splitHash(url) {
|
|
@@ -877,7 +877,7 @@ var SURFACE_KINDS, BROWSER_TIERS, DEFAULT_VIEWPORT, SETTLE_TIMEOUT_MS, SETTLE_QU
|
|
|
877
877
|
var init_browser = __esm({
|
|
878
878
|
"src/worlds/browser.ts"() {
|
|
879
879
|
"use strict";
|
|
880
|
-
|
|
880
|
+
init_session2();
|
|
881
881
|
init_browserReconnect();
|
|
882
882
|
SURFACE_KINDS = ["tools", "api", "ui", "browser"];
|
|
883
883
|
BROWSER_TIERS = ["standard", "premium"];
|
|
@@ -1023,6 +1023,10 @@ var init_browser = __esm({
|
|
|
1023
1023
|
get agentId() {
|
|
1024
1024
|
return this.recorder?.agentId ?? null;
|
|
1025
1025
|
}
|
|
1026
|
+
/** `text` with this session's credentials (UI token, browser address) removed. */
|
|
1027
|
+
scrub(text2) {
|
|
1028
|
+
return this.scrubber.scrub(text2);
|
|
1029
|
+
}
|
|
1026
1030
|
watchNetwork(page) {
|
|
1027
1031
|
page.on("request", () => {
|
|
1028
1032
|
this.inflight += 1;
|
|
@@ -1309,6 +1313,1269 @@ var init_browser = __esm({
|
|
|
1309
1313
|
}
|
|
1310
1314
|
});
|
|
1311
1315
|
|
|
1316
|
+
// src/worlds/nativeComputer/actions.ts
|
|
1317
|
+
function toNumber(value) {
|
|
1318
|
+
if (typeof value !== "number" || !Number.isFinite(value))
|
|
1319
|
+
throw new Error(`not a number: ${JSON.stringify(value) ?? String(value)}`);
|
|
1320
|
+
return value;
|
|
1321
|
+
}
|
|
1322
|
+
function toInt(value) {
|
|
1323
|
+
return Math.trunc(toNumber(value));
|
|
1324
|
+
}
|
|
1325
|
+
var ACTION_NAMES, SECRET_TEXT, BOUNDS, ComputerAction;
|
|
1326
|
+
var init_actions = __esm({
|
|
1327
|
+
"src/worlds/nativeComputer/actions.ts"() {
|
|
1328
|
+
"use strict";
|
|
1329
|
+
ACTION_NAMES = [
|
|
1330
|
+
"screenshot",
|
|
1331
|
+
"zoom",
|
|
1332
|
+
"click",
|
|
1333
|
+
"move",
|
|
1334
|
+
"mouse_down",
|
|
1335
|
+
"mouse_up",
|
|
1336
|
+
"drag",
|
|
1337
|
+
"scroll",
|
|
1338
|
+
"type",
|
|
1339
|
+
"key",
|
|
1340
|
+
"hold_key",
|
|
1341
|
+
"wait",
|
|
1342
|
+
"cursor_position",
|
|
1343
|
+
"history"
|
|
1344
|
+
];
|
|
1345
|
+
SECRET_TEXT = "[redacted]";
|
|
1346
|
+
BOUNDS = {
|
|
1347
|
+
seconds: [0, 300],
|
|
1348
|
+
repeat: [1, 100],
|
|
1349
|
+
count: [1, 3],
|
|
1350
|
+
dx: [-1e4, 1e4],
|
|
1351
|
+
dy: [-1e4, 1e4]
|
|
1352
|
+
};
|
|
1353
|
+
ComputerAction = class {
|
|
1354
|
+
constructor(name, args = {}) {
|
|
1355
|
+
this.name = name;
|
|
1356
|
+
this.args = args;
|
|
1357
|
+
if (!ACTION_NAMES.includes(name))
|
|
1358
|
+
throw new Error(`unknown computer action: ${name}`);
|
|
1359
|
+
for (const [key2, [low, high]] of Object.entries(BOUNDS)) {
|
|
1360
|
+
const value = args[key2];
|
|
1361
|
+
if (value !== void 0 && !(Number(value) >= low && Number(value) <= high))
|
|
1362
|
+
throw new Error(
|
|
1363
|
+
`${name} ${key2} must be between ${low} and ${high}, got ${String(value)}`
|
|
1364
|
+
);
|
|
1365
|
+
}
|
|
1366
|
+
}
|
|
1367
|
+
name;
|
|
1368
|
+
args;
|
|
1369
|
+
/** Flat arguments for the browser timeline and the trace: lists become
|
|
1370
|
+
* `"x,y"` strings, and typed text is withheld when it went into a
|
|
1371
|
+
* credential field. */
|
|
1372
|
+
recordArgs(secretText) {
|
|
1373
|
+
const out = {};
|
|
1374
|
+
for (const [key2, value] of Object.entries(this.args))
|
|
1375
|
+
out[key2] = Array.isArray(value) ? value.flat().join(",") : value;
|
|
1376
|
+
if (secretText && "text" in out) out.text = SECRET_TEXT;
|
|
1377
|
+
return out;
|
|
1378
|
+
}
|
|
1379
|
+
};
|
|
1380
|
+
}
|
|
1381
|
+
});
|
|
1382
|
+
|
|
1383
|
+
// src/worlds/nativeComputer/display.ts
|
|
1384
|
+
var FIT_STEP, Display;
|
|
1385
|
+
var init_display = __esm({
|
|
1386
|
+
"src/worlds/nativeComputer/display.ts"() {
|
|
1387
|
+
"use strict";
|
|
1388
|
+
FIT_STEP = 0.98;
|
|
1389
|
+
Display = class _Display {
|
|
1390
|
+
constructor(width, height, viewportWidth, viewportHeight) {
|
|
1391
|
+
this.width = width;
|
|
1392
|
+
this.height = height;
|
|
1393
|
+
this.viewportWidth = viewportWidth;
|
|
1394
|
+
this.viewportHeight = viewportHeight;
|
|
1395
|
+
}
|
|
1396
|
+
width;
|
|
1397
|
+
height;
|
|
1398
|
+
viewportWidth;
|
|
1399
|
+
viewportHeight;
|
|
1400
|
+
/** `size` when the caller names one; otherwise the largest downscale of the
|
|
1401
|
+
* viewport (at most 1:1) that `fits` the provider's limits. */
|
|
1402
|
+
static forViewport(viewport, size, fits = () => true) {
|
|
1403
|
+
const { width, height } = viewport;
|
|
1404
|
+
if (size) return _Display.sized(size[0], size[1], width, height);
|
|
1405
|
+
let scale = 1;
|
|
1406
|
+
while (!fits(Math.round(width * scale), Math.round(height * scale)))
|
|
1407
|
+
scale *= FIT_STEP;
|
|
1408
|
+
return new _Display(
|
|
1409
|
+
Math.round(width * scale),
|
|
1410
|
+
Math.round(height * scale),
|
|
1411
|
+
width,
|
|
1412
|
+
height
|
|
1413
|
+
);
|
|
1414
|
+
}
|
|
1415
|
+
/** A caller's display keeps the viewport's shape: screenshots are scaled
|
|
1416
|
+
* uniformly, so another aspect ratio would map clicks off the image. */
|
|
1417
|
+
static sized(width, height, viewportWidth, viewportHeight) {
|
|
1418
|
+
if (width <= 0 || height <= 0)
|
|
1419
|
+
throw new Error(`display ${width}x${height} must be positive`);
|
|
1420
|
+
const sameShape = width * viewportHeight / viewportWidth;
|
|
1421
|
+
if (Math.abs(sameShape - height) > 1)
|
|
1422
|
+
throw new Error(
|
|
1423
|
+
`display ${width}x${height} must keep the viewport's aspect ratio (${viewportWidth}x${viewportHeight}); try ${width}x${Math.round(sameShape)}`
|
|
1424
|
+
);
|
|
1425
|
+
return new _Display(width, height, viewportWidth, viewportHeight);
|
|
1426
|
+
}
|
|
1427
|
+
get scaled() {
|
|
1428
|
+
return this.width !== this.viewportWidth || this.height !== this.viewportHeight;
|
|
1429
|
+
}
|
|
1430
|
+
get scale() {
|
|
1431
|
+
return Math.min(
|
|
1432
|
+
this.width / this.viewportWidth,
|
|
1433
|
+
this.height / this.viewportHeight
|
|
1434
|
+
);
|
|
1435
|
+
}
|
|
1436
|
+
toPage(x, y) {
|
|
1437
|
+
return [
|
|
1438
|
+
x * this.viewportWidth / this.width,
|
|
1439
|
+
y * this.viewportHeight / this.height
|
|
1440
|
+
];
|
|
1441
|
+
}
|
|
1442
|
+
};
|
|
1443
|
+
}
|
|
1444
|
+
});
|
|
1445
|
+
|
|
1446
|
+
// src/worlds/nativeComputer/screen.ts
|
|
1447
|
+
function pngWidth(png) {
|
|
1448
|
+
if (png.length < 24 || !png.subarray(0, 8).equals(PNG_SIGNATURE)) return null;
|
|
1449
|
+
return png.readUInt32BE(16);
|
|
1450
|
+
}
|
|
1451
|
+
function isNativePage(page) {
|
|
1452
|
+
const candidate = page;
|
|
1453
|
+
const mouse = candidate?.mouse;
|
|
1454
|
+
return typeof candidate?.context === "function" && NATIVE_METHODS.every((m) => typeof mouse?.[m] === "function");
|
|
1455
|
+
}
|
|
1456
|
+
var FOCUSED_FIELD_JS, SECRET_FOCUS, DRAG_STEPS, PNG_SIGNATURE, NATIVE_METHODS, Screen;
|
|
1457
|
+
var init_screen = __esm({
|
|
1458
|
+
"src/worlds/nativeComputer/screen.ts"() {
|
|
1459
|
+
"use strict";
|
|
1460
|
+
init_browser();
|
|
1461
|
+
FOCUSED_FIELD_JS = "(() => { let e = document.activeElement; const inner = (el) => (el.shadowRoot && el.shadowRoot.activeElement) || (el.contentDocument && el.contentDocument.activeElement); while (e && inner(e)) e = inner(e); if (!e) return ''; if (e.tagName === 'IFRAME' || e.tagName === 'FRAME') return 'frame'; if (!(e.tagName === 'INPUT' || e.tagName === 'TEXTAREA' || e.isContentEditable)) return 'opaque'; return [e.type, e.name, e.id, e.getAttribute('autocomplete')].filter(Boolean).join(' '); })()";
|
|
1462
|
+
SECRET_FOCUS = ["password", "frame", "opaque"];
|
|
1463
|
+
DRAG_STEPS = 5;
|
|
1464
|
+
PNG_SIGNATURE = Buffer.from([
|
|
1465
|
+
137,
|
|
1466
|
+
80,
|
|
1467
|
+
78,
|
|
1468
|
+
71,
|
|
1469
|
+
13,
|
|
1470
|
+
10,
|
|
1471
|
+
26,
|
|
1472
|
+
10
|
|
1473
|
+
]);
|
|
1474
|
+
NATIVE_METHODS = ["move", "click", "down", "up", "wheel"];
|
|
1475
|
+
Screen = class {
|
|
1476
|
+
constructor(browser, display) {
|
|
1477
|
+
this.browser = browser;
|
|
1478
|
+
this.display = display;
|
|
1479
|
+
}
|
|
1480
|
+
browser;
|
|
1481
|
+
display;
|
|
1482
|
+
cursor = [0, 0];
|
|
1483
|
+
pixelRatio = 1;
|
|
1484
|
+
handlers = {
|
|
1485
|
+
screenshot: async () => ({ image: await this.screenshot() }),
|
|
1486
|
+
zoom: (a) => this.zoom(a),
|
|
1487
|
+
click: (a) => this.click(a),
|
|
1488
|
+
move: (a) => this.held(a.args.modifiers ?? [], () => this.moveTo(this.point(a))),
|
|
1489
|
+
mouse_down: async (a) => {
|
|
1490
|
+
await this.page.mouse.down({ button: a.args.button ?? "left" });
|
|
1491
|
+
return {};
|
|
1492
|
+
},
|
|
1493
|
+
mouse_up: async (a) => {
|
|
1494
|
+
await this.page.mouse.up({ button: a.args.button ?? "left" });
|
|
1495
|
+
return {};
|
|
1496
|
+
},
|
|
1497
|
+
drag: (a) => this.drag(a),
|
|
1498
|
+
scroll: (a) => this.scroll(a),
|
|
1499
|
+
type: async (a) => {
|
|
1500
|
+
await this.page.keyboard.type(a.args.text ?? "");
|
|
1501
|
+
return {};
|
|
1502
|
+
},
|
|
1503
|
+
key: (a) => this.key(a),
|
|
1504
|
+
hold_key: (a) => this.held(
|
|
1505
|
+
a.args.keys ?? [],
|
|
1506
|
+
() => this.page.waitForTimeout((a.args.seconds ?? 0) * 1e3)
|
|
1507
|
+
),
|
|
1508
|
+
wait: async (a) => {
|
|
1509
|
+
await this.page.waitForTimeout((a.args.seconds ?? 0) * 1e3);
|
|
1510
|
+
return {};
|
|
1511
|
+
},
|
|
1512
|
+
cursor_position: async () => ({
|
|
1513
|
+
text: `X=${this.cursor[0]}, Y=${this.cursor[1]}`
|
|
1514
|
+
}),
|
|
1515
|
+
history: async (a) => {
|
|
1516
|
+
const navigate = {
|
|
1517
|
+
back: () => this.page.goBack(),
|
|
1518
|
+
forward: () => this.page.goForward()
|
|
1519
|
+
};
|
|
1520
|
+
await navigate[a.args.direction ?? "back"]();
|
|
1521
|
+
return {};
|
|
1522
|
+
}
|
|
1523
|
+
};
|
|
1524
|
+
/** The live page (a new object after a reconnect), as pixel-level Playwright. */
|
|
1525
|
+
get page() {
|
|
1526
|
+
const page = this.browser.page;
|
|
1527
|
+
if (!isNativePage(page))
|
|
1528
|
+
throw new Error(
|
|
1529
|
+
"native computer use needs a Playwright page (mouse.move/click/down/up/wheel, context())"
|
|
1530
|
+
);
|
|
1531
|
+
return page;
|
|
1532
|
+
}
|
|
1533
|
+
run(action) {
|
|
1534
|
+
return this.handlers[action.name](action);
|
|
1535
|
+
}
|
|
1536
|
+
/** A PNG of the viewport at the model's display size. */
|
|
1537
|
+
async screenshot() {
|
|
1538
|
+
if (!this.display.scaled) return this.page.screenshot({ type: "png" });
|
|
1539
|
+
const { viewportWidth: width, viewportHeight: height } = this.display;
|
|
1540
|
+
return this.capture({ x: 0, y: 0, width, height }, this.display.scale);
|
|
1541
|
+
}
|
|
1542
|
+
/** Whether keystrokes go to a credential field (a password input, or one
|
|
1543
|
+
* named like a token, key or PIN), looking through shadow roots and
|
|
1544
|
+
* same-origin frames. An unreadable page, a cross-origin frame or a focus
|
|
1545
|
+
* that is not a text field (a closed shadow root's host) counts as one. */
|
|
1546
|
+
async focusedFieldIsSecret() {
|
|
1547
|
+
let described;
|
|
1548
|
+
try {
|
|
1549
|
+
described = String(await this.page.evaluate(FOCUSED_FIELD_JS) ?? "");
|
|
1550
|
+
} catch {
|
|
1551
|
+
return true;
|
|
1552
|
+
}
|
|
1553
|
+
return SECRET_FOCUS.some((prefix) => described.startsWith(prefix)) || SECRET_KEY.test(described);
|
|
1554
|
+
}
|
|
1555
|
+
/** CDP renders a clip at the page's device pixel ratio as well as its
|
|
1556
|
+
* `scale` (a Retina host doubles it), so a capture of the wrong width
|
|
1557
|
+
* measures that ratio and is taken once more, corrected. */
|
|
1558
|
+
async capture(clip, scale) {
|
|
1559
|
+
const wanted = Math.round(clip.width * scale);
|
|
1560
|
+
const png = await this.cdpCapture(clip, scale / this.pixelRatio);
|
|
1561
|
+
const width = pngWidth(png);
|
|
1562
|
+
if (width === null || Math.abs(width - wanted) <= 1) return png;
|
|
1563
|
+
this.pixelRatio *= width / wanted;
|
|
1564
|
+
return this.cdpCapture(clip, scale / this.pixelRatio);
|
|
1565
|
+
}
|
|
1566
|
+
async cdpCapture(clip, scale) {
|
|
1567
|
+
const page = this.page;
|
|
1568
|
+
const session = await page.context().newCDPSession(page);
|
|
1569
|
+
try {
|
|
1570
|
+
const shot = await session.send("Page.captureScreenshot", {
|
|
1571
|
+
format: "png",
|
|
1572
|
+
clip: { ...clip, scale }
|
|
1573
|
+
});
|
|
1574
|
+
return Buffer.from(shot.data, "base64");
|
|
1575
|
+
} finally {
|
|
1576
|
+
await session.detach();
|
|
1577
|
+
}
|
|
1578
|
+
}
|
|
1579
|
+
point(action) {
|
|
1580
|
+
const { x, y } = action.args;
|
|
1581
|
+
return x === void 0 || y === void 0 ? this.cursor : [x, y];
|
|
1582
|
+
}
|
|
1583
|
+
async moveTo(point2, steps = 1) {
|
|
1584
|
+
const [x, y] = this.display.toPage(point2[0], point2[1]);
|
|
1585
|
+
await this.page.mouse.move(x, y, { steps });
|
|
1586
|
+
this.cursor = point2;
|
|
1587
|
+
}
|
|
1588
|
+
async held(modifiers, fn) {
|
|
1589
|
+
for (const key2 of modifiers) await this.page.keyboard.down(key2);
|
|
1590
|
+
try {
|
|
1591
|
+
await fn();
|
|
1592
|
+
} finally {
|
|
1593
|
+
for (const key2 of [...modifiers].reverse())
|
|
1594
|
+
await this.page.keyboard.up(key2);
|
|
1595
|
+
}
|
|
1596
|
+
return {};
|
|
1597
|
+
}
|
|
1598
|
+
async zoom(action) {
|
|
1599
|
+
const [x0, y0, x1, y1] = action.args.region ?? [0, 0, 0, 0];
|
|
1600
|
+
const [left, top] = this.display.toPage(x0, y0);
|
|
1601
|
+
const [right, bottom] = this.display.toPage(x1, y1);
|
|
1602
|
+
if (right <= left || bottom <= top)
|
|
1603
|
+
throw new Error("zoom region must have x1 > x0 and y1 > y0");
|
|
1604
|
+
const width = right - left;
|
|
1605
|
+
const height = bottom - top;
|
|
1606
|
+
const scale = Math.min(
|
|
1607
|
+
this.display.width / width,
|
|
1608
|
+
this.display.height / height
|
|
1609
|
+
);
|
|
1610
|
+
return {
|
|
1611
|
+
image: await this.capture({ x: left, y: top, width, height }, scale)
|
|
1612
|
+
};
|
|
1613
|
+
}
|
|
1614
|
+
async click(action) {
|
|
1615
|
+
const point2 = this.point(action);
|
|
1616
|
+
return this.held(action.args.modifiers ?? [], async () => {
|
|
1617
|
+
await this.moveTo(point2);
|
|
1618
|
+
const [x, y] = this.display.toPage(point2[0], point2[1]);
|
|
1619
|
+
await this.page.mouse.click(x, y, {
|
|
1620
|
+
button: action.args.button ?? "left",
|
|
1621
|
+
clickCount: action.args.count ?? 1
|
|
1622
|
+
});
|
|
1623
|
+
});
|
|
1624
|
+
}
|
|
1625
|
+
async drag(action) {
|
|
1626
|
+
const path16 = action.args.path ?? [];
|
|
1627
|
+
if (path16.length < 2) throw new Error("a drag needs at least two points");
|
|
1628
|
+
return this.held(action.args.modifiers ?? [], async () => {
|
|
1629
|
+
await this.moveTo(path16[0]);
|
|
1630
|
+
await this.page.mouse.down({ button: "left" });
|
|
1631
|
+
try {
|
|
1632
|
+
for (const point2 of path16.slice(1)) await this.moveTo(point2, DRAG_STEPS);
|
|
1633
|
+
} finally {
|
|
1634
|
+
await this.page.mouse.up({ button: "left" });
|
|
1635
|
+
}
|
|
1636
|
+
});
|
|
1637
|
+
}
|
|
1638
|
+
async scroll(action) {
|
|
1639
|
+
await this.moveTo(this.point(action));
|
|
1640
|
+
const scale = this.display.scale;
|
|
1641
|
+
return this.held(
|
|
1642
|
+
action.args.modifiers ?? [],
|
|
1643
|
+
() => this.page.mouse.wheel(
|
|
1644
|
+
(action.args.dx ?? 0) / scale,
|
|
1645
|
+
(action.args.dy ?? 0) / scale
|
|
1646
|
+
)
|
|
1647
|
+
);
|
|
1648
|
+
}
|
|
1649
|
+
async key(action) {
|
|
1650
|
+
const combo = (action.args.keys ?? []).join("+");
|
|
1651
|
+
for (let i = 0; i < (action.args.repeat ?? 1); i += 1)
|
|
1652
|
+
await this.page.keyboard.press(combo);
|
|
1653
|
+
return {};
|
|
1654
|
+
}
|
|
1655
|
+
};
|
|
1656
|
+
}
|
|
1657
|
+
});
|
|
1658
|
+
|
|
1659
|
+
// src/tracing/media.ts
|
|
1660
|
+
import { createHash as createHash2 } from "crypto";
|
|
1661
|
+
async function putBytes(url, data, headers) {
|
|
1662
|
+
const controller = new AbortController();
|
|
1663
|
+
const timer = setTimeout(() => controller.abort(), PUT_TIMEOUT_MS);
|
|
1664
|
+
try {
|
|
1665
|
+
const res = await fetch(url, {
|
|
1666
|
+
method: "PUT",
|
|
1667
|
+
body: new Uint8Array(data),
|
|
1668
|
+
headers,
|
|
1669
|
+
signal: controller.signal
|
|
1670
|
+
});
|
|
1671
|
+
return {
|
|
1672
|
+
status: res.status,
|
|
1673
|
+
error: res.ok ? null : (await res.text()).slice(0, MAX_UPLOAD_ERROR)
|
|
1674
|
+
};
|
|
1675
|
+
} catch (error) {
|
|
1676
|
+
return {
|
|
1677
|
+
status: NETWORK_FAILURE_STATUS,
|
|
1678
|
+
error: error instanceof Error ? error.name : "Error"
|
|
1679
|
+
};
|
|
1680
|
+
} finally {
|
|
1681
|
+
clearTimeout(timer);
|
|
1682
|
+
}
|
|
1683
|
+
}
|
|
1684
|
+
var MEDIA_PATH, MAX_MEDIA_BYTES, PUT_TIMEOUT_MS, MAX_UPLOAD_ERROR, NETWORK_FAILURE_STATUS, MediaUploadError, MediaReference, MediaUploader;
|
|
1685
|
+
var init_media = __esm({
|
|
1686
|
+
"src/tracing/media.ts"() {
|
|
1687
|
+
"use strict";
|
|
1688
|
+
init_transport();
|
|
1689
|
+
MEDIA_PATH = "/api/public/media";
|
|
1690
|
+
MAX_MEDIA_BYTES = 5 * 1024 * 1024;
|
|
1691
|
+
PUT_TIMEOUT_MS = 3e4;
|
|
1692
|
+
MAX_UPLOAD_ERROR = 500;
|
|
1693
|
+
NETWORK_FAILURE_STATUS = 599;
|
|
1694
|
+
MediaUploadError = class extends Error {
|
|
1695
|
+
constructor(message, status) {
|
|
1696
|
+
super(message);
|
|
1697
|
+
this.status = status;
|
|
1698
|
+
this.name = "MediaUploadError";
|
|
1699
|
+
}
|
|
1700
|
+
status;
|
|
1701
|
+
};
|
|
1702
|
+
MediaReference = class {
|
|
1703
|
+
constructor(mediaId, contentType) {
|
|
1704
|
+
this.mediaId = mediaId;
|
|
1705
|
+
this.contentType = contentType;
|
|
1706
|
+
}
|
|
1707
|
+
mediaId;
|
|
1708
|
+
contentType;
|
|
1709
|
+
toString() {
|
|
1710
|
+
return `@@@langfuseMedia:type=${this.contentType}|id=${this.mediaId}|source=bytes@@@`;
|
|
1711
|
+
}
|
|
1712
|
+
};
|
|
1713
|
+
MediaUploader = class _MediaUploader {
|
|
1714
|
+
constructor(transport, put = putBytes, maxBytes = MAX_MEDIA_BYTES) {
|
|
1715
|
+
this.transport = transport;
|
|
1716
|
+
this.put = put;
|
|
1717
|
+
this.maxBytes = maxBytes;
|
|
1718
|
+
}
|
|
1719
|
+
transport;
|
|
1720
|
+
put;
|
|
1721
|
+
maxBytes;
|
|
1722
|
+
/** The uploader for `GATEWAY_HOST` / `GATEWAY_PUBLIC_KEY` /
|
|
1723
|
+
* `GATEWAY_SECRET_KEY` (the keys tracing exports with); null when any is unset. */
|
|
1724
|
+
static fromEnv(env = process.env) {
|
|
1725
|
+
const host = env.GATEWAY_HOST;
|
|
1726
|
+
const publicKey = env.GATEWAY_PUBLIC_KEY;
|
|
1727
|
+
const secretKey = env.GATEWAY_SECRET_KEY;
|
|
1728
|
+
if (!host || !publicKey || !secretKey) return null;
|
|
1729
|
+
return new _MediaUploader(
|
|
1730
|
+
new PlatformTransport({
|
|
1731
|
+
host: host.replace(/\/$/, ""),
|
|
1732
|
+
publicKey,
|
|
1733
|
+
secretKey
|
|
1734
|
+
})
|
|
1735
|
+
);
|
|
1736
|
+
}
|
|
1737
|
+
/** Store `data` linked to the trace (and observation) and return its reference. */
|
|
1738
|
+
async upload(data, link) {
|
|
1739
|
+
if (data.length > this.maxBytes)
|
|
1740
|
+
throw new MediaUploadError(
|
|
1741
|
+
`media is ${data.length} bytes, over the ${this.maxBytes}-byte cap`
|
|
1742
|
+
);
|
|
1743
|
+
const sha256Hash = createHash2("sha256").update(data).digest("base64");
|
|
1744
|
+
const answer = await this.send("POST", MEDIA_PATH, {
|
|
1745
|
+
traceId: link.traceId,
|
|
1746
|
+
observationId: link.observationId,
|
|
1747
|
+
contentType: link.contentType,
|
|
1748
|
+
contentLength: data.length,
|
|
1749
|
+
sha256Hash,
|
|
1750
|
+
field: link.field
|
|
1751
|
+
});
|
|
1752
|
+
if (typeof answer.mediaId !== "string" || !answer.mediaId)
|
|
1753
|
+
throw new MediaUploadError(
|
|
1754
|
+
"POST /api/public/media answered without a mediaId"
|
|
1755
|
+
);
|
|
1756
|
+
const reference = new MediaReference(answer.mediaId, link.contentType);
|
|
1757
|
+
if (answer.uploadUrl)
|
|
1758
|
+
await this.store(reference, answer.uploadUrl, data, sha256Hash);
|
|
1759
|
+
return reference;
|
|
1760
|
+
}
|
|
1761
|
+
async store(reference, url, data, sha256Hash) {
|
|
1762
|
+
const started = Date.now();
|
|
1763
|
+
const { status, error } = await this.put(url, data, {
|
|
1764
|
+
"Content-Type": reference.contentType,
|
|
1765
|
+
"x-amz-checksum-sha256": sha256Hash,
|
|
1766
|
+
"x-ms-blob-type": "BlockBlob"
|
|
1767
|
+
});
|
|
1768
|
+
await this.send(
|
|
1769
|
+
"PATCH",
|
|
1770
|
+
`${MEDIA_PATH}/${encodeURIComponent(reference.mediaId)}`,
|
|
1771
|
+
{
|
|
1772
|
+
uploadedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1773
|
+
uploadHttpStatus: status,
|
|
1774
|
+
uploadHttpError: error,
|
|
1775
|
+
uploadTimeMs: Date.now() - started
|
|
1776
|
+
}
|
|
1777
|
+
);
|
|
1778
|
+
if (status < 200 || status >= 300)
|
|
1779
|
+
throw new MediaUploadError(
|
|
1780
|
+
`media storage refused the upload (HTTP ${status})`,
|
|
1781
|
+
status
|
|
1782
|
+
);
|
|
1783
|
+
}
|
|
1784
|
+
async send(method, route, body) {
|
|
1785
|
+
const reply = await this.transport.send(method, route, body);
|
|
1786
|
+
if (!reply.ok)
|
|
1787
|
+
throw new MediaUploadError(
|
|
1788
|
+
`${method} ${route} -> ${reply.status}`,
|
|
1789
|
+
reply.status
|
|
1790
|
+
);
|
|
1791
|
+
return reply.text ? JSON.parse(reply.text) : {};
|
|
1792
|
+
}
|
|
1793
|
+
};
|
|
1794
|
+
}
|
|
1795
|
+
});
|
|
1796
|
+
|
|
1797
|
+
// src/worlds/nativeComputer/trace.ts
|
|
1798
|
+
function loadOtelApi() {
|
|
1799
|
+
if (otelApi !== void 0) return otelApi;
|
|
1800
|
+
try {
|
|
1801
|
+
otelApi = __require("@opentelemetry/api");
|
|
1802
|
+
} catch {
|
|
1803
|
+
otelApi = null;
|
|
1804
|
+
}
|
|
1805
|
+
return otelApi;
|
|
1806
|
+
}
|
|
1807
|
+
function errorText(error) {
|
|
1808
|
+
return error instanceof Error ? `${error.name}: ${error.message}` : String(error);
|
|
1809
|
+
}
|
|
1810
|
+
function errorName(error) {
|
|
1811
|
+
return error instanceof Error ? error.name : "Error";
|
|
1812
|
+
}
|
|
1813
|
+
var SPAN_PREFIX, MAX_UPLOAD_FAILURES, TRACER_NAME, MAX_ERROR, otelApi, ActionTracer;
|
|
1814
|
+
var init_trace = __esm({
|
|
1815
|
+
"src/worlds/nativeComputer/trace.ts"() {
|
|
1816
|
+
"use strict";
|
|
1817
|
+
init_media();
|
|
1818
|
+
SPAN_PREFIX = "computer.";
|
|
1819
|
+
MAX_UPLOAD_FAILURES = 3;
|
|
1820
|
+
TRACER_NAME = "@withgateway/sdk";
|
|
1821
|
+
MAX_ERROR = 1e3;
|
|
1822
|
+
ActionTracer = class _ActionTracer {
|
|
1823
|
+
constructor(media, warn3 = (m) => console.warn(m)) {
|
|
1824
|
+
this.media = media;
|
|
1825
|
+
this.warn = warn3;
|
|
1826
|
+
}
|
|
1827
|
+
media;
|
|
1828
|
+
warn;
|
|
1829
|
+
failures = 0;
|
|
1830
|
+
warned = false;
|
|
1831
|
+
static fromEnv() {
|
|
1832
|
+
return new _ActionTracer(MediaUploader.fromEnv());
|
|
1833
|
+
}
|
|
1834
|
+
/** `args` are already redacted. A failure's status goes through `scrub`:
|
|
1835
|
+
* browser errors quote the session's ws URL and UI token. */
|
|
1836
|
+
async span(action, args, run, capture, scrub) {
|
|
1837
|
+
const otel = loadOtelApi();
|
|
1838
|
+
if (!otel) return run();
|
|
1839
|
+
const { SpanStatusCode: SpanStatusCode3, trace: trace5 } = otel;
|
|
1840
|
+
const attributes = {
|
|
1841
|
+
"gateway.observation.type": "tool",
|
|
1842
|
+
"tool.name": SPAN_PREFIX + action.name,
|
|
1843
|
+
"gateway.observation.input": JSON.stringify({
|
|
1844
|
+
action: action.name,
|
|
1845
|
+
...args
|
|
1846
|
+
})
|
|
1847
|
+
};
|
|
1848
|
+
return trace5.getTracer(TRACER_NAME).startActiveSpan(
|
|
1849
|
+
SPAN_PREFIX + action.name,
|
|
1850
|
+
{ attributes },
|
|
1851
|
+
async (span) => {
|
|
1852
|
+
try {
|
|
1853
|
+
const result = await run();
|
|
1854
|
+
await this.finish(span, result, capture);
|
|
1855
|
+
span.setStatus({ code: SpanStatusCode3.OK });
|
|
1856
|
+
return result;
|
|
1857
|
+
} catch (error) {
|
|
1858
|
+
span.setStatus({
|
|
1859
|
+
code: SpanStatusCode3.ERROR,
|
|
1860
|
+
message: scrub(errorText(error)).slice(0, MAX_ERROR)
|
|
1861
|
+
});
|
|
1862
|
+
throw error;
|
|
1863
|
+
} finally {
|
|
1864
|
+
span.end();
|
|
1865
|
+
}
|
|
1866
|
+
}
|
|
1867
|
+
);
|
|
1868
|
+
}
|
|
1869
|
+
async finish(span, result, capture) {
|
|
1870
|
+
if (!span.isRecording()) return;
|
|
1871
|
+
const output = {
|
|
1872
|
+
screenshot: await this.screenshot(span, result, capture)
|
|
1873
|
+
};
|
|
1874
|
+
if (result.text !== void 0) output.text = result.text;
|
|
1875
|
+
span.setAttribute("gateway.observation.output", JSON.stringify(output));
|
|
1876
|
+
}
|
|
1877
|
+
async screenshot(span, result, capture) {
|
|
1878
|
+
let png;
|
|
1879
|
+
try {
|
|
1880
|
+
png = result.image ?? await capture();
|
|
1881
|
+
} catch (error) {
|
|
1882
|
+
return `[screenshot unavailable: ${errorName(error)}]`;
|
|
1883
|
+
}
|
|
1884
|
+
return this.reference(png, span);
|
|
1885
|
+
}
|
|
1886
|
+
async reference(png, span) {
|
|
1887
|
+
if (!this.media)
|
|
1888
|
+
return "[screenshot not uploaded: GATEWAY_HOST / GATEWAY_PUBLIC_KEY / GATEWAY_SECRET_KEY unset]";
|
|
1889
|
+
if (this.failures >= MAX_UPLOAD_FAILURES)
|
|
1890
|
+
return "[screenshot not uploaded: uploads disabled after repeated failures]";
|
|
1891
|
+
const { traceId, spanId } = span.spanContext();
|
|
1892
|
+
try {
|
|
1893
|
+
const reference = await this.media.upload(png, {
|
|
1894
|
+
contentType: "image/png",
|
|
1895
|
+
traceId,
|
|
1896
|
+
observationId: spanId,
|
|
1897
|
+
field: "output"
|
|
1898
|
+
});
|
|
1899
|
+
this.failures = 0;
|
|
1900
|
+
return reference.toString();
|
|
1901
|
+
} catch (error) {
|
|
1902
|
+
return this.failed(error);
|
|
1903
|
+
}
|
|
1904
|
+
}
|
|
1905
|
+
failed(error) {
|
|
1906
|
+
this.failures += 1;
|
|
1907
|
+
if (!this.warned) {
|
|
1908
|
+
this.warned = true;
|
|
1909
|
+
this.warn(
|
|
1910
|
+
`native computer: screenshot upload failed (${errorName(error)}: ${error instanceof Error ? error.message : String(error)}); spans keep going without it`
|
|
1911
|
+
);
|
|
1912
|
+
}
|
|
1913
|
+
return `[screenshot not uploaded: ${errorName(error)}]`;
|
|
1914
|
+
}
|
|
1915
|
+
};
|
|
1916
|
+
}
|
|
1917
|
+
});
|
|
1918
|
+
|
|
1919
|
+
// src/worlds/nativeComputer/base.ts
|
|
1920
|
+
function readField(item, ...names) {
|
|
1921
|
+
const record = item ?? {};
|
|
1922
|
+
return names.map((name) => record[name]).find((value) => value !== void 0 && value !== null);
|
|
1923
|
+
}
|
|
1924
|
+
var REPLAYABLE, SETTLING, EVENT_PREFIX, NativeComputer;
|
|
1925
|
+
var init_base = __esm({
|
|
1926
|
+
"src/worlds/nativeComputer/base.ts"() {
|
|
1927
|
+
"use strict";
|
|
1928
|
+
init_browser();
|
|
1929
|
+
init_actions();
|
|
1930
|
+
init_display();
|
|
1931
|
+
init_screen();
|
|
1932
|
+
init_trace();
|
|
1933
|
+
REPLAYABLE = /* @__PURE__ */ new Set(["screenshot", "zoom", "cursor_position", "wait"]);
|
|
1934
|
+
SETTLING = /* @__PURE__ */ new Set(["click", "mouse_up", "drag", "key", "history"]);
|
|
1935
|
+
EVENT_PREFIX = "computer_";
|
|
1936
|
+
NativeComputer = class _NativeComputer {
|
|
1937
|
+
constructor(browser, options = {}) {
|
|
1938
|
+
this.browser = browser;
|
|
1939
|
+
const kind = this.constructor;
|
|
1940
|
+
this.display = Display.forViewport(
|
|
1941
|
+
browser.viewport,
|
|
1942
|
+
options.display,
|
|
1943
|
+
(w, h) => kind.fits(w, h)
|
|
1944
|
+
);
|
|
1945
|
+
this.screen = new Screen(browser, this.display);
|
|
1946
|
+
this.tracer = options.tracer ?? ActionTracer.fromEnv();
|
|
1947
|
+
}
|
|
1948
|
+
browser;
|
|
1949
|
+
static kinds = /* @__PURE__ */ new Map();
|
|
1950
|
+
display;
|
|
1951
|
+
screen;
|
|
1952
|
+
tracer;
|
|
1953
|
+
queue = Promise.resolve();
|
|
1954
|
+
static register(provider, kind) {
|
|
1955
|
+
_NativeComputer.kinds.set(provider, kind);
|
|
1956
|
+
}
|
|
1957
|
+
static get providers() {
|
|
1958
|
+
return [..._NativeComputer.kinds.keys()].sort();
|
|
1959
|
+
}
|
|
1960
|
+
static forProvider(provider, browser, options = {}) {
|
|
1961
|
+
const Kind = _NativeComputer.kinds.get(provider);
|
|
1962
|
+
if (!Kind)
|
|
1963
|
+
throw new Error(
|
|
1964
|
+
`unknown computer-use provider '${provider}'; choose from ${_NativeComputer.providers.join(", ")}`
|
|
1965
|
+
);
|
|
1966
|
+
return new Kind(browser, options);
|
|
1967
|
+
}
|
|
1968
|
+
/** Whether a screenshot of this size is within the provider's limits. */
|
|
1969
|
+
static fits(_width, _height) {
|
|
1970
|
+
return true;
|
|
1971
|
+
}
|
|
1972
|
+
/** Run one provider-shaped action (an OpenAI action object, or an Anthropic
|
|
1973
|
+
* `{ action: "left_click", ... }` input) and return what it produced: the
|
|
1974
|
+
* door for any agent framework that hands actions over one at a time. */
|
|
1975
|
+
executeAction(raw) {
|
|
1976
|
+
return this.perform(this.parse(raw));
|
|
1977
|
+
}
|
|
1978
|
+
/** Run one action on the page: reported on the session's browser timeline
|
|
1979
|
+
* and, when tracing is on, as a span with the screen after. */
|
|
1980
|
+
async perform(action) {
|
|
1981
|
+
const secret = action.name === "type" && await this.screen.focusedFieldIsSecret();
|
|
1982
|
+
const event = EVENT_PREFIX + action.name;
|
|
1983
|
+
const args = redactActionArgs(event, action.recordArgs(secret));
|
|
1984
|
+
return this.tracer.span(
|
|
1985
|
+
action,
|
|
1986
|
+
args,
|
|
1987
|
+
() => this.browser.act(
|
|
1988
|
+
event,
|
|
1989
|
+
args,
|
|
1990
|
+
() => this.runOnScreen(action),
|
|
1991
|
+
this.onLoss(action)
|
|
1992
|
+
),
|
|
1993
|
+
() => this.screen.screenshot(),
|
|
1994
|
+
(text2) => this.browser.scrub(text2)
|
|
1995
|
+
);
|
|
1996
|
+
}
|
|
1997
|
+
async performAll(actions) {
|
|
1998
|
+
const results = [];
|
|
1999
|
+
for (const action of actions) results.push(await this.perform(action));
|
|
2000
|
+
return results;
|
|
2001
|
+
}
|
|
2002
|
+
/** The screen as the model sees it, as a traced `screenshot` action. */
|
|
2003
|
+
async screenshot() {
|
|
2004
|
+
return (await this.perform(new ComputerAction("screenshot"))).image ?? Buffer.alloc(0);
|
|
2005
|
+
}
|
|
2006
|
+
/** Run `fn` after every earlier call made through here: the AI SDK starts a
|
|
2007
|
+
* step's tool calls concurrently, but one screen takes one action at a time. */
|
|
2008
|
+
serial(fn) {
|
|
2009
|
+
const next = this.queue.then(fn, fn);
|
|
2010
|
+
this.queue = next.catch(() => void 0);
|
|
2011
|
+
return next;
|
|
2012
|
+
}
|
|
2013
|
+
async runOnScreen(action) {
|
|
2014
|
+
const result = await this.screen.run(action);
|
|
2015
|
+
if (SETTLING.has(action.name)) await this.browser.settle();
|
|
2016
|
+
return result;
|
|
2017
|
+
}
|
|
2018
|
+
onLoss(action) {
|
|
2019
|
+
return REPLAYABLE.has(action.name) ? "retry" : "report";
|
|
2020
|
+
}
|
|
2021
|
+
};
|
|
2022
|
+
}
|
|
2023
|
+
});
|
|
2024
|
+
|
|
2025
|
+
// src/worlds/nativeComputer/keys.ts
|
|
2026
|
+
function playwrightKey(token) {
|
|
2027
|
+
return KEY_NAMES[token.toLowerCase()] ?? token;
|
|
2028
|
+
}
|
|
2029
|
+
function letterOrName(key2) {
|
|
2030
|
+
return /^[a-zA-Z]$/.test(key2) ? key2.toLowerCase() : playwrightKey(key2);
|
|
2031
|
+
}
|
|
2032
|
+
function modifierChord(text2) {
|
|
2033
|
+
return typeof text2 === "string" && text2 ? [...KeyChord.fromXdotool(text2).keys] : [];
|
|
2034
|
+
}
|
|
2035
|
+
function modifierKeys(keys) {
|
|
2036
|
+
return Array.isArray(keys) && keys.length > 0 ? [...KeyChord.fromKeys(keys.map(String)).keys] : [];
|
|
2037
|
+
}
|
|
2038
|
+
var F_KEYS, KEY_NAMES, KeyChord;
|
|
2039
|
+
var init_keys = __esm({
|
|
2040
|
+
"src/worlds/nativeComputer/keys.ts"() {
|
|
2041
|
+
"use strict";
|
|
2042
|
+
F_KEYS = Object.fromEntries(
|
|
2043
|
+
Array.from({ length: 12 }, (_, i) => [`f${i + 1}`, `F${i + 1}`])
|
|
2044
|
+
);
|
|
2045
|
+
KEY_NAMES = {
|
|
2046
|
+
return: "Enter",
|
|
2047
|
+
enter: "Enter",
|
|
2048
|
+
kp_enter: "Enter",
|
|
2049
|
+
esc: "Escape",
|
|
2050
|
+
escape: "Escape",
|
|
2051
|
+
tab: "Tab",
|
|
2052
|
+
space: "Space",
|
|
2053
|
+
backspace: "Backspace",
|
|
2054
|
+
delete: "Delete",
|
|
2055
|
+
del: "Delete",
|
|
2056
|
+
insert: "Insert",
|
|
2057
|
+
home: "Home",
|
|
2058
|
+
end: "End",
|
|
2059
|
+
pageup: "PageUp",
|
|
2060
|
+
page_up: "PageUp",
|
|
2061
|
+
prior: "PageUp",
|
|
2062
|
+
pagedown: "PageDown",
|
|
2063
|
+
page_down: "PageDown",
|
|
2064
|
+
next: "PageDown",
|
|
2065
|
+
up: "ArrowUp",
|
|
2066
|
+
arrowup: "ArrowUp",
|
|
2067
|
+
down: "ArrowDown",
|
|
2068
|
+
arrowdown: "ArrowDown",
|
|
2069
|
+
left: "ArrowLeft",
|
|
2070
|
+
arrowleft: "ArrowLeft",
|
|
2071
|
+
right: "ArrowRight",
|
|
2072
|
+
arrowright: "ArrowRight",
|
|
2073
|
+
ctrl: "Control",
|
|
2074
|
+
control: "Control",
|
|
2075
|
+
shift: "Shift",
|
|
2076
|
+
alt: "Alt",
|
|
2077
|
+
option: "Alt",
|
|
2078
|
+
super: "Meta",
|
|
2079
|
+
meta: "Meta",
|
|
2080
|
+
cmd: "Meta",
|
|
2081
|
+
command: "Meta",
|
|
2082
|
+
win: "Meta",
|
|
2083
|
+
capslock: "CapsLock",
|
|
2084
|
+
caps_lock: "CapsLock",
|
|
2085
|
+
plus: "+",
|
|
2086
|
+
minus: "-",
|
|
2087
|
+
...F_KEYS
|
|
2088
|
+
};
|
|
2089
|
+
KeyChord = class _KeyChord {
|
|
2090
|
+
constructor(keys) {
|
|
2091
|
+
this.keys = keys;
|
|
2092
|
+
if (keys.length === 0)
|
|
2093
|
+
throw new Error("a key action needs at least one key");
|
|
2094
|
+
}
|
|
2095
|
+
keys;
|
|
2096
|
+
/** `ctrl+shift+t` / `Return`: Anthropic's vocabulary, case kept. */
|
|
2097
|
+
static fromXdotool(text2) {
|
|
2098
|
+
return new _KeyChord(
|
|
2099
|
+
text2.trim().split("+").filter(Boolean).map(playwrightKey)
|
|
2100
|
+
);
|
|
2101
|
+
}
|
|
2102
|
+
/** `["CTRL", "A"]`: OpenAI's vocabulary. A lone letter is the unshifted key. */
|
|
2103
|
+
static fromKeys(keys) {
|
|
2104
|
+
return new _KeyChord(keys.map(letterOrName));
|
|
2105
|
+
}
|
|
2106
|
+
/** What `page.keyboard.press` takes: `Control+a`. */
|
|
2107
|
+
get combo() {
|
|
2108
|
+
return this.keys.join("+");
|
|
2109
|
+
}
|
|
2110
|
+
};
|
|
2111
|
+
}
|
|
2112
|
+
});
|
|
2113
|
+
|
|
2114
|
+
// src/worlds/nativeComputer/anthropic.ts
|
|
2115
|
+
function required(raw, key2) {
|
|
2116
|
+
const value = raw[key2];
|
|
2117
|
+
if (value === void 0 || value === null)
|
|
2118
|
+
throw new Error(`${String(raw.action)} needs ${key2}`);
|
|
2119
|
+
return value;
|
|
2120
|
+
}
|
|
2121
|
+
function pair(raw, key2) {
|
|
2122
|
+
const value = required(raw, key2);
|
|
2123
|
+
return [toInt(value[0]), toInt(value[1])];
|
|
2124
|
+
}
|
|
2125
|
+
function point(raw) {
|
|
2126
|
+
if (raw.coordinate === void 0 || raw.coordinate === null) return {};
|
|
2127
|
+
const [x, y] = pair(raw, "coordinate");
|
|
2128
|
+
return { x, y };
|
|
2129
|
+
}
|
|
2130
|
+
function chord(raw) {
|
|
2131
|
+
return [...KeyChord.fromXdotool(String(required(raw, "text"))).keys];
|
|
2132
|
+
}
|
|
2133
|
+
function click(button, count) {
|
|
2134
|
+
return (raw) => new ComputerAction("click", {
|
|
2135
|
+
...point(raw),
|
|
2136
|
+
button,
|
|
2137
|
+
count,
|
|
2138
|
+
modifiers: modifierChord(raw.text)
|
|
2139
|
+
});
|
|
2140
|
+
}
|
|
2141
|
+
var SCROLL_STEP_PX, NOT_EXECUTED, MAX_ERROR2, SCROLL_DIRECTIONS, MEMBERS, AnthropicComputer, AnthropicComputer20251124;
|
|
2142
|
+
var init_anthropic = __esm({
|
|
2143
|
+
"src/worlds/nativeComputer/anthropic.ts"() {
|
|
2144
|
+
"use strict";
|
|
2145
|
+
init_actions();
|
|
2146
|
+
init_base();
|
|
2147
|
+
init_keys();
|
|
2148
|
+
SCROLL_STEP_PX = 100;
|
|
2149
|
+
NOT_EXECUTED = "Not executed: an earlier computer action in this turn failed.";
|
|
2150
|
+
MAX_ERROR2 = 1e3;
|
|
2151
|
+
SCROLL_DIRECTIONS = {
|
|
2152
|
+
up: [0, -1],
|
|
2153
|
+
down: [0, 1],
|
|
2154
|
+
left: [-1, 0],
|
|
2155
|
+
right: [1, 0]
|
|
2156
|
+
};
|
|
2157
|
+
MEMBERS = {
|
|
2158
|
+
screenshot: () => new ComputerAction("screenshot"),
|
|
2159
|
+
zoom: (raw) => new ComputerAction("zoom", {
|
|
2160
|
+
region: required(raw, "region").map(toInt)
|
|
2161
|
+
}),
|
|
2162
|
+
left_click: click("left", 1),
|
|
2163
|
+
right_click: click("right", 1),
|
|
2164
|
+
middle_click: click("middle", 1),
|
|
2165
|
+
double_click: click("left", 2),
|
|
2166
|
+
triple_click: click("left", 3),
|
|
2167
|
+
left_click_drag: (raw) => new ComputerAction("drag", {
|
|
2168
|
+
path: [pair(raw, "start_coordinate"), pair(raw, "coordinate")],
|
|
2169
|
+
modifiers: modifierChord(raw.text)
|
|
2170
|
+
}),
|
|
2171
|
+
mouse_move: (raw) => {
|
|
2172
|
+
const [x, y] = pair(raw, "coordinate");
|
|
2173
|
+
return new ComputerAction("move", { x, y });
|
|
2174
|
+
},
|
|
2175
|
+
left_mouse_down: () => new ComputerAction("mouse_down", { button: "left" }),
|
|
2176
|
+
left_mouse_up: () => new ComputerAction("mouse_up", { button: "left" }),
|
|
2177
|
+
cursor_position: () => new ComputerAction("cursor_position"),
|
|
2178
|
+
scroll: (raw) => {
|
|
2179
|
+
const direction = String(raw.scroll_direction ?? "down");
|
|
2180
|
+
if (!Object.hasOwn(SCROLL_DIRECTIONS, direction))
|
|
2181
|
+
throw new Error(
|
|
2182
|
+
`scroll_direction must be one of ${Object.keys(SCROLL_DIRECTIONS).join(", ")}`
|
|
2183
|
+
);
|
|
2184
|
+
const [dx, dy] = SCROLL_DIRECTIONS[direction];
|
|
2185
|
+
const amount = toInt(raw.scroll_amount ?? 1) * SCROLL_STEP_PX;
|
|
2186
|
+
return new ComputerAction("scroll", {
|
|
2187
|
+
...point(raw),
|
|
2188
|
+
dx: dx * amount,
|
|
2189
|
+
dy: dy * amount,
|
|
2190
|
+
modifiers: modifierChord(raw.text)
|
|
2191
|
+
});
|
|
2192
|
+
},
|
|
2193
|
+
type: (raw) => new ComputerAction("type", { text: String(required(raw, "text")) }),
|
|
2194
|
+
key: (raw) => new ComputerAction("key", {
|
|
2195
|
+
keys: chord(raw),
|
|
2196
|
+
repeat: toInt(raw.repeat ?? 1)
|
|
2197
|
+
}),
|
|
2198
|
+
hold_key: (raw) => new ComputerAction("hold_key", {
|
|
2199
|
+
keys: chord(raw),
|
|
2200
|
+
seconds: toNumber(required(raw, "duration"))
|
|
2201
|
+
}),
|
|
2202
|
+
wait: (raw) => new ComputerAction("wait", { seconds: toNumber(raw.duration ?? 1) })
|
|
2203
|
+
};
|
|
2204
|
+
AnthropicComputer = class _AnthropicComputer extends NativeComputer {
|
|
2205
|
+
static TOOL_TYPE = "computer_toolset_20260801";
|
|
2206
|
+
static TOOLSET = "computer";
|
|
2207
|
+
static BETA = null;
|
|
2208
|
+
static MAX_LONG_EDGE = 2576;
|
|
2209
|
+
static MAX_VISUAL_TOKENS = 4784;
|
|
2210
|
+
static PATCH_PX = 28;
|
|
2211
|
+
static fits(width, height) {
|
|
2212
|
+
const tokens = Math.ceil(width / this.PATCH_PX) * Math.ceil(height / this.PATCH_PX);
|
|
2213
|
+
return Math.max(width, height) <= this.MAX_LONG_EDGE && tokens <= this.MAX_VISUAL_TOKENS;
|
|
2214
|
+
}
|
|
2215
|
+
tool() {
|
|
2216
|
+
return { type: _AnthropicComputer.TOOL_TYPE };
|
|
2217
|
+
}
|
|
2218
|
+
/** Whether a content block is a call to this computer. */
|
|
2219
|
+
owns(block) {
|
|
2220
|
+
return readField(block, "type") === "tool_use" && readField(block, "toolset_name") === _AnthropicComputer.TOOLSET;
|
|
2221
|
+
}
|
|
2222
|
+
member(block) {
|
|
2223
|
+
return [
|
|
2224
|
+
String(readField(block, "name")),
|
|
2225
|
+
{ ...readField(block, "input") ?? {} }
|
|
2226
|
+
];
|
|
2227
|
+
}
|
|
2228
|
+
parse(raw) {
|
|
2229
|
+
const name = String(readField(raw, "action"));
|
|
2230
|
+
const parser = Object.hasOwn(MEMBERS, name) ? MEMBERS[name] : void 0;
|
|
2231
|
+
if (!parser) throw new Error(`unknown computer action: ${name}`);
|
|
2232
|
+
return parser(raw);
|
|
2233
|
+
}
|
|
2234
|
+
/** Run every computer `tool_use` in a response's content, in order, and
|
|
2235
|
+
* return one `tool_result` per block. Other blocks are skipped. */
|
|
2236
|
+
async execute(content) {
|
|
2237
|
+
const results = [];
|
|
2238
|
+
let failed = false;
|
|
2239
|
+
for (const block of content) {
|
|
2240
|
+
if (!this.owns(block)) continue;
|
|
2241
|
+
if (failed) {
|
|
2242
|
+
results.push(this.envelope(block, NOT_EXECUTED, true));
|
|
2243
|
+
continue;
|
|
2244
|
+
}
|
|
2245
|
+
const [result, blockFailed] = await this.runBlock(block);
|
|
2246
|
+
results.push(result);
|
|
2247
|
+
failed = blockFailed;
|
|
2248
|
+
}
|
|
2249
|
+
return results;
|
|
2250
|
+
}
|
|
2251
|
+
/** The content an `ActionResult` goes back to the model as. */
|
|
2252
|
+
static content(result) {
|
|
2253
|
+
if (result.image)
|
|
2254
|
+
return [
|
|
2255
|
+
{
|
|
2256
|
+
type: "image",
|
|
2257
|
+
source: {
|
|
2258
|
+
type: "base64",
|
|
2259
|
+
media_type: "image/png",
|
|
2260
|
+
data: result.image.toString("base64")
|
|
2261
|
+
}
|
|
2262
|
+
}
|
|
2263
|
+
];
|
|
2264
|
+
return [{ type: "text", text: result.text ?? "OK" }];
|
|
2265
|
+
}
|
|
2266
|
+
/** For `anthropic.tools.computerToolset_20260801({ ...computer.aiSdk() })`
|
|
2267
|
+
* (or `computer_20251124` with the legacy kind): `execute` runs one action
|
|
2268
|
+
* and returns `{ type: "image", data }` or text; `toModelOutput` turns that
|
|
2269
|
+
* into the tool result. Calls run one at a time, and once a call fails the
|
|
2270
|
+
* rest of that step's calls answer as not executed. */
|
|
2271
|
+
aiSdk() {
|
|
2272
|
+
let failedStep;
|
|
2273
|
+
const execute = (input, options) => this.serial(async () => {
|
|
2274
|
+
const step = options?.messages?.length;
|
|
2275
|
+
if (step !== void 0 && step === failedStep)
|
|
2276
|
+
throw new Error(NOT_EXECUTED);
|
|
2277
|
+
try {
|
|
2278
|
+
return _AnthropicComputer.aiSdkOutput(await this.executeAction(input));
|
|
2279
|
+
} catch (error) {
|
|
2280
|
+
failedStep = step;
|
|
2281
|
+
throw error instanceof Error ? new Error(this.browser.scrub(error.message)) : error;
|
|
2282
|
+
}
|
|
2283
|
+
});
|
|
2284
|
+
return {
|
|
2285
|
+
execute,
|
|
2286
|
+
toModelOutput: ({ output }) => _AnthropicComputer.aiSdkModelOutput(output)
|
|
2287
|
+
};
|
|
2288
|
+
}
|
|
2289
|
+
static aiSdkOutput(result) {
|
|
2290
|
+
if (result.image)
|
|
2291
|
+
return { type: "image", data: result.image.toString("base64") };
|
|
2292
|
+
return result.text ?? "OK";
|
|
2293
|
+
}
|
|
2294
|
+
/** `image-data` is what AI SDK 6's Anthropic provider turns into an image
|
|
2295
|
+
* block; AI SDK 7 still accepts it (and converts it to a `file` part). */
|
|
2296
|
+
static aiSdkModelOutput(output) {
|
|
2297
|
+
if (typeof output === "string") return { type: "text", value: output };
|
|
2298
|
+
return {
|
|
2299
|
+
type: "content",
|
|
2300
|
+
value: [
|
|
2301
|
+
{ type: "image-data", data: output.data, mediaType: "image/png" }
|
|
2302
|
+
]
|
|
2303
|
+
};
|
|
2304
|
+
}
|
|
2305
|
+
envelope(block, content, isError = false) {
|
|
2306
|
+
return {
|
|
2307
|
+
type: "tool_result",
|
|
2308
|
+
tool_use_id: String(readField(block, "id")),
|
|
2309
|
+
toolset_name: _AnthropicComputer.TOOLSET,
|
|
2310
|
+
content,
|
|
2311
|
+
...isError ? { is_error: true } : {}
|
|
2312
|
+
};
|
|
2313
|
+
}
|
|
2314
|
+
async runBlock(block) {
|
|
2315
|
+
const [name, payload] = this.member(block);
|
|
2316
|
+
try {
|
|
2317
|
+
const result = await this.executeAction({ ...payload, action: name });
|
|
2318
|
+
return [this.envelope(block, _AnthropicComputer.content(result)), false];
|
|
2319
|
+
} catch (error) {
|
|
2320
|
+
const detail = error instanceof Error ? `${error.name}: ${error.message}` : String(error);
|
|
2321
|
+
return [
|
|
2322
|
+
this.envelope(
|
|
2323
|
+
block,
|
|
2324
|
+
this.browser.scrub(`Error: ${detail}`).slice(0, MAX_ERROR2),
|
|
2325
|
+
true
|
|
2326
|
+
),
|
|
2327
|
+
true
|
|
2328
|
+
];
|
|
2329
|
+
}
|
|
2330
|
+
}
|
|
2331
|
+
};
|
|
2332
|
+
AnthropicComputer20251124 = class _AnthropicComputer20251124 extends AnthropicComputer {
|
|
2333
|
+
static TOOL_TYPE = "computer_20251124";
|
|
2334
|
+
static BETA = "computer-use-2025-11-24";
|
|
2335
|
+
static MAX_LONG_EDGE = 1568;
|
|
2336
|
+
static MAX_PIXELS = 115e4;
|
|
2337
|
+
static fits(width, height) {
|
|
2338
|
+
return Math.max(width, height) <= this.MAX_LONG_EDGE && width * height <= this.MAX_PIXELS;
|
|
2339
|
+
}
|
|
2340
|
+
tool() {
|
|
2341
|
+
return {
|
|
2342
|
+
type: _AnthropicComputer20251124.TOOL_TYPE,
|
|
2343
|
+
name: AnthropicComputer.TOOLSET,
|
|
2344
|
+
display_width_px: this.display.width,
|
|
2345
|
+
display_height_px: this.display.height,
|
|
2346
|
+
enable_zoom: true
|
|
2347
|
+
};
|
|
2348
|
+
}
|
|
2349
|
+
owns(block) {
|
|
2350
|
+
return readField(block, "type") === "tool_use" && readField(block, "name") === AnthropicComputer.TOOLSET;
|
|
2351
|
+
}
|
|
2352
|
+
member(block) {
|
|
2353
|
+
const { action, ...payload } = readField(block, "input") ?? {};
|
|
2354
|
+
return [String(action ?? ""), payload];
|
|
2355
|
+
}
|
|
2356
|
+
envelope(block, content, isError = false) {
|
|
2357
|
+
const { toolset_name: _dropped, ...rest } = super.envelope(
|
|
2358
|
+
block,
|
|
2359
|
+
content,
|
|
2360
|
+
isError
|
|
2361
|
+
);
|
|
2362
|
+
return rest;
|
|
2363
|
+
}
|
|
2364
|
+
};
|
|
2365
|
+
NativeComputer.register("anthropic", AnthropicComputer);
|
|
2366
|
+
NativeComputer.register(
|
|
2367
|
+
"anthropic-computer-20251124",
|
|
2368
|
+
AnthropicComputer20251124
|
|
2369
|
+
);
|
|
2370
|
+
}
|
|
2371
|
+
});
|
|
2372
|
+
|
|
2373
|
+
// src/worlds/nativeComputer/openai.ts
|
|
2374
|
+
function safetyCheck(raw) {
|
|
2375
|
+
const check = { id: String(readField(raw, "id") ?? "") };
|
|
2376
|
+
const code = readField(raw, "code");
|
|
2377
|
+
const message = readField(raw, "message");
|
|
2378
|
+
if (code !== void 0) check.code = String(code);
|
|
2379
|
+
if (message !== void 0) check.message = String(message);
|
|
2380
|
+
return check;
|
|
2381
|
+
}
|
|
2382
|
+
function dataUrl(png) {
|
|
2383
|
+
return `data:image/png;base64,${png.toString("base64")}`;
|
|
2384
|
+
}
|
|
2385
|
+
function xy(raw) {
|
|
2386
|
+
return {
|
|
2387
|
+
x: toInt(readField(raw, "x") ?? 0),
|
|
2388
|
+
y: toInt(readField(raw, "y") ?? 0)
|
|
2389
|
+
};
|
|
2390
|
+
}
|
|
2391
|
+
function held(raw) {
|
|
2392
|
+
return modifierKeys(readField(raw, "keys"));
|
|
2393
|
+
}
|
|
2394
|
+
var WAIT_SECONDS, BUTTONS, HISTORY_BUTTONS, PendingSafetyChecks, ACTIONS, OpenAIComputer, OpenAIPreviewComputer;
|
|
2395
|
+
var init_openai = __esm({
|
|
2396
|
+
"src/worlds/nativeComputer/openai.ts"() {
|
|
2397
|
+
"use strict";
|
|
2398
|
+
init_actions();
|
|
2399
|
+
init_base();
|
|
2400
|
+
init_keys();
|
|
2401
|
+
WAIT_SECONDS = 1;
|
|
2402
|
+
BUTTONS = {
|
|
2403
|
+
left: "left",
|
|
2404
|
+
right: "right",
|
|
2405
|
+
wheel: "middle",
|
|
2406
|
+
middle: "middle"
|
|
2407
|
+
};
|
|
2408
|
+
HISTORY_BUTTONS = /* @__PURE__ */ new Set(["back", "forward"]);
|
|
2409
|
+
PendingSafetyChecks = class extends Error {
|
|
2410
|
+
constructor(callId, checks) {
|
|
2411
|
+
const listed = checks.map((c) => `${c.code ?? "check"}: ${c.message ?? ""}`.trim()).join("; ");
|
|
2412
|
+
super(
|
|
2413
|
+
`computer_call ${callId} needs ${checks.length} safety check(s) acknowledged: ${listed}`
|
|
2414
|
+
);
|
|
2415
|
+
this.callId = callId;
|
|
2416
|
+
this.checks = checks;
|
|
2417
|
+
this.name = "PendingSafetyChecks";
|
|
2418
|
+
}
|
|
2419
|
+
callId;
|
|
2420
|
+
checks;
|
|
2421
|
+
};
|
|
2422
|
+
ACTIONS = {
|
|
2423
|
+
click: (raw) => {
|
|
2424
|
+
const button = String(readField(raw, "button") ?? "left");
|
|
2425
|
+
if (HISTORY_BUTTONS.has(button))
|
|
2426
|
+
return new ComputerAction("history", {
|
|
2427
|
+
direction: button
|
|
2428
|
+
});
|
|
2429
|
+
if (!Object.hasOwn(BUTTONS, button))
|
|
2430
|
+
throw new Error(`unknown mouse button: ${button}`);
|
|
2431
|
+
return new ComputerAction("click", {
|
|
2432
|
+
...xy(raw),
|
|
2433
|
+
button: BUTTONS[button],
|
|
2434
|
+
count: 1,
|
|
2435
|
+
modifiers: held(raw)
|
|
2436
|
+
});
|
|
2437
|
+
},
|
|
2438
|
+
double_click: (raw) => new ComputerAction("click", {
|
|
2439
|
+
...xy(raw),
|
|
2440
|
+
button: "left",
|
|
2441
|
+
count: 2,
|
|
2442
|
+
modifiers: held(raw)
|
|
2443
|
+
}),
|
|
2444
|
+
drag: (raw) => new ComputerAction("drag", {
|
|
2445
|
+
path: (readField(raw, "path") ?? []).map(
|
|
2446
|
+
(p) => [toInt(readField(p, "x")), toInt(readField(p, "y"))]
|
|
2447
|
+
),
|
|
2448
|
+
modifiers: held(raw)
|
|
2449
|
+
}),
|
|
2450
|
+
keypress: (raw) => new ComputerAction("key", {
|
|
2451
|
+
keys: [
|
|
2452
|
+
...KeyChord.fromKeys(readField(raw, "keys") ?? []).keys
|
|
2453
|
+
],
|
|
2454
|
+
repeat: 1
|
|
2455
|
+
}),
|
|
2456
|
+
move: (raw) => new ComputerAction("move", { ...xy(raw), modifiers: held(raw) }),
|
|
2457
|
+
scroll: (raw) => new ComputerAction("scroll", {
|
|
2458
|
+
...xy(raw),
|
|
2459
|
+
dx: toInt(readField(raw, "scroll_x", "scrollX") ?? 0),
|
|
2460
|
+
dy: toInt(readField(raw, "scroll_y", "scrollY") ?? 0),
|
|
2461
|
+
modifiers: held(raw)
|
|
2462
|
+
}),
|
|
2463
|
+
type: (raw) => new ComputerAction("type", { text: String(readField(raw, "text") ?? "") }),
|
|
2464
|
+
wait: () => new ComputerAction("wait", { seconds: WAIT_SECONDS }),
|
|
2465
|
+
screenshot: () => new ComputerAction("screenshot")
|
|
2466
|
+
};
|
|
2467
|
+
OpenAIComputer = class _OpenAIComputer extends NativeComputer {
|
|
2468
|
+
tool() {
|
|
2469
|
+
return { type: "computer" };
|
|
2470
|
+
}
|
|
2471
|
+
owns(item) {
|
|
2472
|
+
return readField(item, "type") === "computer_call";
|
|
2473
|
+
}
|
|
2474
|
+
parse(raw) {
|
|
2475
|
+
const kind = String(readField(raw, "type"));
|
|
2476
|
+
const parser = Object.hasOwn(ACTIONS, kind) ? ACTIONS[kind] : void 0;
|
|
2477
|
+
if (!parser) throw new Error(`unknown computer action: ${kind}`);
|
|
2478
|
+
return parser(raw);
|
|
2479
|
+
}
|
|
2480
|
+
static actionsOf(call) {
|
|
2481
|
+
const batch = readField(call, "actions");
|
|
2482
|
+
if (Array.isArray(batch)) return batch;
|
|
2483
|
+
const single = readField(call, "action");
|
|
2484
|
+
return single === void 0 ? [] : [single];
|
|
2485
|
+
}
|
|
2486
|
+
/** Run a `computer_call`'s actions and return its `computer_call_output`.
|
|
2487
|
+
* Throws `PendingSafetyChecks` (before anything runs) while a check the
|
|
2488
|
+
* model raised is not in `acknowledged`. */
|
|
2489
|
+
async execute(call, acknowledged = []) {
|
|
2490
|
+
const callId = String(readField(call, "call_id", "callId"));
|
|
2491
|
+
const checks = (readField(
|
|
2492
|
+
call,
|
|
2493
|
+
"pending_safety_checks",
|
|
2494
|
+
"pendingSafetyChecks"
|
|
2495
|
+
) ?? []).map(safetyCheck);
|
|
2496
|
+
const png = await this.runCall(
|
|
2497
|
+
callId,
|
|
2498
|
+
_OpenAIComputer.actionsOf(call),
|
|
2499
|
+
checks,
|
|
2500
|
+
acknowledged
|
|
2501
|
+
);
|
|
2502
|
+
return {
|
|
2503
|
+
type: "computer_call_output",
|
|
2504
|
+
call_id: callId,
|
|
2505
|
+
output: {
|
|
2506
|
+
type: "computer_screenshot",
|
|
2507
|
+
image_url: dataUrl(png),
|
|
2508
|
+
detail: "original"
|
|
2509
|
+
},
|
|
2510
|
+
...checks.length > 0 ? { acknowledged_safety_checks: checks } : {}
|
|
2511
|
+
};
|
|
2512
|
+
}
|
|
2513
|
+
/** For `openai.tools.computer({ ...computer.aiSdk() })`: `execute` runs a
|
|
2514
|
+
* call's `actions` and returns the screenshot output. A call with pending
|
|
2515
|
+
* safety checks asks for approval first (`needsApproval`), so the AI SDK's
|
|
2516
|
+
* approval flow puts them in front of a person; once approved, `execute`
|
|
2517
|
+
* acknowledges them. */
|
|
2518
|
+
aiSdk() {
|
|
2519
|
+
return {
|
|
2520
|
+
needsApproval: (input) => (input.pendingSafetyChecks ?? []).length > 0,
|
|
2521
|
+
execute: (input) => this.serial(async () => {
|
|
2522
|
+
const checks = (input.pendingSafetyChecks ?? []).map(safetyCheck);
|
|
2523
|
+
const png = await this.runCall(
|
|
2524
|
+
"ai-sdk",
|
|
2525
|
+
input.actions ?? [],
|
|
2526
|
+
checks,
|
|
2527
|
+
checks
|
|
2528
|
+
);
|
|
2529
|
+
return {
|
|
2530
|
+
output: { type: "computer_screenshot", imageUrl: dataUrl(png) },
|
|
2531
|
+
...checks.length > 0 ? { acknowledgedSafetyChecks: checks } : {}
|
|
2532
|
+
};
|
|
2533
|
+
})
|
|
2534
|
+
};
|
|
2535
|
+
}
|
|
2536
|
+
/** The batch's actions, run after the safety checks clear; the screen after them. */
|
|
2537
|
+
async runCall(callId, rawActions, checks, acknowledged) {
|
|
2538
|
+
const cleared = new Set(acknowledged.map((c) => safetyCheck(c).id));
|
|
2539
|
+
const waiting = checks.filter((c) => !c.id || !cleared.has(c.id));
|
|
2540
|
+
if (waiting.length > 0) throw new PendingSafetyChecks(callId, waiting);
|
|
2541
|
+
const actions = rawActions.map((raw) => this.parse(raw));
|
|
2542
|
+
const results = await this.performAll(actions);
|
|
2543
|
+
const last = actions.at(-1);
|
|
2544
|
+
if (last?.name === "screenshot")
|
|
2545
|
+
return results.at(-1)?.image ?? Buffer.alloc(0);
|
|
2546
|
+
return this.screenshot();
|
|
2547
|
+
}
|
|
2548
|
+
};
|
|
2549
|
+
OpenAIPreviewComputer = class extends OpenAIComputer {
|
|
2550
|
+
tool() {
|
|
2551
|
+
return {
|
|
2552
|
+
type: "computer_use_preview",
|
|
2553
|
+
display_width: this.display.width,
|
|
2554
|
+
display_height: this.display.height,
|
|
2555
|
+
environment: "browser"
|
|
2556
|
+
};
|
|
2557
|
+
}
|
|
2558
|
+
};
|
|
2559
|
+
NativeComputer.register("openai", OpenAIComputer);
|
|
2560
|
+
NativeComputer.register("openai-preview", OpenAIPreviewComputer);
|
|
2561
|
+
}
|
|
2562
|
+
});
|
|
2563
|
+
|
|
2564
|
+
// src/worlds/nativeComputer/index.ts
|
|
2565
|
+
var init_nativeComputer = __esm({
|
|
2566
|
+
"src/worlds/nativeComputer/index.ts"() {
|
|
2567
|
+
"use strict";
|
|
2568
|
+
init_actions();
|
|
2569
|
+
init_base();
|
|
2570
|
+
init_display();
|
|
2571
|
+
init_keys();
|
|
2572
|
+
init_screen();
|
|
2573
|
+
init_trace();
|
|
2574
|
+
init_anthropic();
|
|
2575
|
+
init_openai();
|
|
2576
|
+
}
|
|
2577
|
+
});
|
|
2578
|
+
|
|
1312
2579
|
// src/worlds/sessionContract.ts
|
|
1313
2580
|
function serializeCallBody(body) {
|
|
1314
2581
|
const text2 = JSON.stringify(body);
|
|
@@ -1362,6 +2629,75 @@ var init_sessionContract = __esm({
|
|
|
1362
2629
|
}
|
|
1363
2630
|
});
|
|
1364
2631
|
|
|
2632
|
+
// src/tracing/session.ts
|
|
2633
|
+
var session_exports = {};
|
|
2634
|
+
__export(session_exports, {
|
|
2635
|
+
SESSION_ID_ATTRIBUTE: () => SESSION_ID_ATTRIBUTE,
|
|
2636
|
+
SessionSpanProcessor: () => SessionSpanProcessor,
|
|
2637
|
+
WORLD_SESSION_ID_ATTRIBUTE: () => WORLD_SESSION_ID_ATTRIBUTE,
|
|
2638
|
+
getAmbientSessionId: () => getAmbientSessionId,
|
|
2639
|
+
getCurrentWorldSessionId: () => getCurrentWorldSessionId,
|
|
2640
|
+
withSession: () => withSession,
|
|
2641
|
+
withWorldSession: () => withWorldSession
|
|
2642
|
+
});
|
|
2643
|
+
import { AsyncLocalStorage as AsyncLocalStorage2 } from "async_hooks";
|
|
2644
|
+
function getAmbientSessionId() {
|
|
2645
|
+
return currentSessionStorage.getStore();
|
|
2646
|
+
}
|
|
2647
|
+
function getCurrentWorldSessionId() {
|
|
2648
|
+
return currentWorldSessionStorage.getStore();
|
|
2649
|
+
}
|
|
2650
|
+
function runIn(storage, value, fn) {
|
|
2651
|
+
return new Promise((resolve11, reject) => {
|
|
2652
|
+
storage.run(value, () => {
|
|
2653
|
+
Promise.resolve().then(fn).then(resolve11, reject);
|
|
2654
|
+
});
|
|
2655
|
+
});
|
|
2656
|
+
}
|
|
2657
|
+
function withSession(sessionId, fn) {
|
|
2658
|
+
return runIn(currentSessionStorage, sessionId, fn);
|
|
2659
|
+
}
|
|
2660
|
+
function withWorldSession(worldSessionId, fn) {
|
|
2661
|
+
return runIn(
|
|
2662
|
+
currentWorldSessionStorage,
|
|
2663
|
+
worldSessionId,
|
|
2664
|
+
() => withSession(worldSessionId, fn)
|
|
2665
|
+
);
|
|
2666
|
+
}
|
|
2667
|
+
var SESSION_ID_ATTRIBUTE, WORLD_SESSION_ID_ATTRIBUTE, processStorage, currentSessionStorage, currentWorldSessionStorage, SessionSpanProcessor;
|
|
2668
|
+
var init_session = __esm({
|
|
2669
|
+
"src/tracing/session.ts"() {
|
|
2670
|
+
"use strict";
|
|
2671
|
+
SESSION_ID_ATTRIBUTE = "gateway.session.id";
|
|
2672
|
+
WORLD_SESSION_ID_ATTRIBUTE = "gateway.trace.metadata.world_session_id";
|
|
2673
|
+
processStorage = (name) => {
|
|
2674
|
+
const key2 = /* @__PURE__ */ Symbol.for(`@withgateway/sdk/${name}`);
|
|
2675
|
+
const slots = globalThis;
|
|
2676
|
+
slots[key2] ??= new AsyncLocalStorage2();
|
|
2677
|
+
return slots[key2];
|
|
2678
|
+
};
|
|
2679
|
+
currentSessionStorage = processStorage("session-storage");
|
|
2680
|
+
currentWorldSessionStorage = processStorage("world-session-storage");
|
|
2681
|
+
SessionSpanProcessor = class {
|
|
2682
|
+
onStart(span, _parentContext) {
|
|
2683
|
+
const worldSessionId = getCurrentWorldSessionId();
|
|
2684
|
+
if (worldSessionId)
|
|
2685
|
+
span.setAttribute(WORLD_SESSION_ID_ATTRIBUTE, worldSessionId);
|
|
2686
|
+
const sessionId = getAmbientSessionId();
|
|
2687
|
+
if (!sessionId || span.attributes?.[SESSION_ID_ATTRIBUTE] !== void 0)
|
|
2688
|
+
return;
|
|
2689
|
+
span.setAttribute(SESSION_ID_ATTRIBUTE, sessionId);
|
|
2690
|
+
}
|
|
2691
|
+
onEnd(_span) {
|
|
2692
|
+
}
|
|
2693
|
+
async shutdown() {
|
|
2694
|
+
}
|
|
2695
|
+
async forceFlush() {
|
|
2696
|
+
}
|
|
2697
|
+
};
|
|
2698
|
+
}
|
|
2699
|
+
});
|
|
2700
|
+
|
|
1365
2701
|
// src/worlds/taskRef.ts
|
|
1366
2702
|
var isTaskIdRef, isTaskSpec, taskLabel, assertTaskRef;
|
|
1367
2703
|
var init_taskRef = __esm({
|
|
@@ -1386,8 +2722,8 @@ var init_taskRef = __esm({
|
|
|
1386
2722
|
});
|
|
1387
2723
|
|
|
1388
2724
|
// src/worlds/session.ts
|
|
1389
|
-
var
|
|
1390
|
-
__export(
|
|
2725
|
+
var session_exports2 = {};
|
|
2726
|
+
__export(session_exports2, {
|
|
1391
2727
|
WorldSession: () => WorldSession,
|
|
1392
2728
|
WorldSessionCallError: () => WorldSessionCallError,
|
|
1393
2729
|
WorldSessionTimeout: () => WorldSessionTimeout,
|
|
@@ -1441,7 +2777,7 @@ function schemaFromSignature(spec) {
|
|
|
1441
2777
|
};
|
|
1442
2778
|
const inside = /\(([\s\S]*)\)\s*$/.exec(spec.signature.trim())?.[1] ?? "";
|
|
1443
2779
|
const properties = {};
|
|
1444
|
-
const
|
|
2780
|
+
const required2 = [];
|
|
1445
2781
|
const params = [];
|
|
1446
2782
|
let depth = 0;
|
|
1447
2783
|
let current = "";
|
|
@@ -1462,7 +2798,7 @@ function schemaFromSignature(spec) {
|
|
|
1462
2798
|
if (!name) continue;
|
|
1463
2799
|
if (eq === -1) {
|
|
1464
2800
|
properties[name] = { type: "string" };
|
|
1465
|
-
|
|
2801
|
+
required2.push(name);
|
|
1466
2802
|
continue;
|
|
1467
2803
|
}
|
|
1468
2804
|
const value = param.slice(eq + 1).trim();
|
|
@@ -1476,7 +2812,7 @@ function schemaFromSignature(spec) {
|
|
|
1476
2812
|
function: {
|
|
1477
2813
|
name: modelToolName(spec.name),
|
|
1478
2814
|
description: spec.doc ?? spec.name,
|
|
1479
|
-
parameters: { type: "object", properties, required }
|
|
2815
|
+
parameters: { type: "object", properties, required: required2 }
|
|
1480
2816
|
}
|
|
1481
2817
|
};
|
|
1482
2818
|
}
|
|
@@ -1545,13 +2881,16 @@ async function runSessions(opts) {
|
|
|
1545
2881
|
task = taskLabel(taskRef, session.taskInfo);
|
|
1546
2882
|
await session.ready();
|
|
1547
2883
|
const toolkit = await session.toolkit();
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
2884
|
+
const live = session;
|
|
2885
|
+
await live.withTraceContext(
|
|
2886
|
+
() => opts.agent({
|
|
2887
|
+
session: live,
|
|
2888
|
+
toolkit,
|
|
2889
|
+
instruction: live.instruction ?? (isTaskSpec(taskRef) ? taskRef.instruction : task),
|
|
2890
|
+
task,
|
|
2891
|
+
taskRef
|
|
2892
|
+
})
|
|
2893
|
+
);
|
|
1555
2894
|
const graded = await session.grade();
|
|
1556
2895
|
const result = {
|
|
1557
2896
|
task,
|
|
@@ -1589,12 +2928,14 @@ async function runSessions(opts) {
|
|
|
1589
2928
|
};
|
|
1590
2929
|
}
|
|
1591
2930
|
var READY_TIMEOUT_MS, READY_POLL_MS, CALL_TIMEOUT_MS, CALL_POLL_MS, JUDGED_GRADE_TIMEOUT_MS, JUDGED_GRADE_POLL_MS, EXPORT_PAGE, sleep2, modelToolName, WorldSessionTimeout, WorldSessionCallError, WorldSession, OPEN_SESSION_OPTION_KEYS, isOpenSessionOptions;
|
|
1592
|
-
var
|
|
2931
|
+
var init_session2 = __esm({
|
|
1593
2932
|
"src/worlds/session.ts"() {
|
|
1594
2933
|
"use strict";
|
|
1595
2934
|
init_worlds();
|
|
1596
2935
|
init_browser();
|
|
2936
|
+
init_nativeComputer();
|
|
1597
2937
|
init_sessionContract();
|
|
2938
|
+
init_session();
|
|
1598
2939
|
init_taskRef();
|
|
1599
2940
|
init_taskRef();
|
|
1600
2941
|
READY_TIMEOUT_MS = 10 * 6e4;
|
|
@@ -1748,6 +3089,12 @@ var init_session = __esm({
|
|
|
1748
3089
|
computerUseTools(browser) {
|
|
1749
3090
|
return computerUseToolkit(browser);
|
|
1750
3091
|
}
|
|
3092
|
+
/** The browser as a provider's own pixel-based computer-use tool: `anthropic`
|
|
3093
|
+
* (`computer_toolset_20260801`), `openai` (Responses `computer`),
|
|
3094
|
+
* `anthropic-computer-20251124` or `openai-preview`. See `nativeComputer/`. */
|
|
3095
|
+
nativeComputer(browser, provider = "anthropic", options = {}) {
|
|
3096
|
+
return NativeComputer.forProvider(provider, browser, options);
|
|
3097
|
+
}
|
|
1751
3098
|
/** The session's latest platform state (one request, no waiting). */
|
|
1752
3099
|
async status() {
|
|
1753
3100
|
const fresh = await apiRequest(
|
|
@@ -1982,6 +3329,21 @@ var init_session = __esm({
|
|
|
1982
3329
|
{ keepWarm: opts.keepWarm ?? false }
|
|
1983
3330
|
);
|
|
1984
3331
|
}
|
|
3332
|
+
/**
|
|
3333
|
+
* Run `fn` as work inside this session: spans it records take `sessionId`
|
|
3334
|
+
* as their session id and carry `world_session_id` trace metadata, so the
|
|
3335
|
+
* agent's traces land in the same session as the platform's traces of this
|
|
3336
|
+
* session's tool calls. A `withSession()` block inside still wins for the
|
|
3337
|
+
* session id. No effect before `tracing.init()`. `runSessions` wraps each
|
|
3338
|
+
* agent call in it.
|
|
3339
|
+
*
|
|
3340
|
+
* ```typescript
|
|
3341
|
+
* await session.withTraceContext(() => myAgent(toolkit, session.instruction));
|
|
3342
|
+
* ```
|
|
3343
|
+
*/
|
|
3344
|
+
withTraceContext(fn) {
|
|
3345
|
+
return withWorldSession(this.sessionId, fn);
|
|
3346
|
+
}
|
|
1985
3347
|
};
|
|
1986
3348
|
OPEN_SESSION_OPTION_KEYS = /* @__PURE__ */ new Set([
|
|
1987
3349
|
"task",
|
|
@@ -2103,6 +3465,28 @@ var init_tasks = __esm({
|
|
|
2103
3465
|
}
|
|
2104
3466
|
});
|
|
2105
3467
|
|
|
3468
|
+
// src/worlds/surfaceDescriptor.ts
|
|
3469
|
+
function surfaceDescriptor(s) {
|
|
3470
|
+
return {
|
|
3471
|
+
surfaces: surfaceKinds(s),
|
|
3472
|
+
...s.api ? { api: { url: s.api.url, ...s.api.token ? { token: s.api.token } : {} } } : {},
|
|
3473
|
+
...s.ui ? { ui: { url: s.ui.url, entry: uiEntryUrl(s.ui), apiPath: s.ui.apiPath ?? null } } : {},
|
|
3474
|
+
...s.browser ? {
|
|
3475
|
+
browser: {
|
|
3476
|
+
wsUrl: s.browser.wsUrl,
|
|
3477
|
+
viewport: s.browser.viewport,
|
|
3478
|
+
...s.browser.tier ? { tier: s.browser.tier } : {}
|
|
3479
|
+
}
|
|
3480
|
+
} : {}
|
|
3481
|
+
};
|
|
3482
|
+
}
|
|
3483
|
+
var init_surfaceDescriptor = __esm({
|
|
3484
|
+
"src/worlds/surfaceDescriptor.ts"() {
|
|
3485
|
+
"use strict";
|
|
3486
|
+
init_browser();
|
|
3487
|
+
}
|
|
3488
|
+
});
|
|
3489
|
+
|
|
2106
3490
|
// src/worlds/taskSessions.ts
|
|
2107
3491
|
function aggregateTaskGrade(worlds) {
|
|
2108
3492
|
const rewards = {};
|
|
@@ -2131,7 +3515,11 @@ function fromResponse(answer, options) {
|
|
|
2131
3515
|
const worlds = {};
|
|
2132
3516
|
for (const [alias, state2] of Object.entries(answer.sessions)) {
|
|
2133
3517
|
sessions2[alias] = new WorldSession(state2.sessionId, state2, options);
|
|
2134
|
-
worlds[alias] = {
|
|
3518
|
+
worlds[alias] = {
|
|
3519
|
+
slug: state2.slug,
|
|
3520
|
+
ref: state2.ref,
|
|
3521
|
+
private: state2.private ?? null
|
|
3522
|
+
};
|
|
2135
3523
|
}
|
|
2136
3524
|
return new TaskSessions(
|
|
2137
3525
|
answer.taskId,
|
|
@@ -2205,6 +3593,7 @@ async function attachTask(taskId, options = {}) {
|
|
|
2205
3593
|
{
|
|
2206
3594
|
slug: row.slug ?? "",
|
|
2207
3595
|
ref: null,
|
|
3596
|
+
private: null,
|
|
2208
3597
|
versionId: row.versionId,
|
|
2209
3598
|
sessionId: row.sessionId,
|
|
2210
3599
|
ready: row.ready,
|
|
@@ -2234,7 +3623,7 @@ async function attachManifest(manifest, options = {}) {
|
|
|
2234
3623
|
Object.fromEntries(
|
|
2235
3624
|
Object.entries(manifest.sessions).map(([alias, entry]) => [
|
|
2236
3625
|
alias,
|
|
2237
|
-
{ slug: entry.slug, ref: entry.ref }
|
|
3626
|
+
{ slug: entry.slug, ref: entry.ref, private: entry.private ?? null }
|
|
2238
3627
|
])
|
|
2239
3628
|
)
|
|
2240
3629
|
);
|
|
@@ -2248,28 +3637,19 @@ var init_taskSessions = __esm({
|
|
|
2248
3637
|
"use strict";
|
|
2249
3638
|
init_worlds();
|
|
2250
3639
|
init_browser();
|
|
2251
|
-
|
|
3640
|
+
init_surfaceDescriptor();
|
|
3641
|
+
init_session2();
|
|
2252
3642
|
TASK_SESSIONS = "/api/public/world-task-sessions";
|
|
2253
3643
|
VERIFIER_REWARD_PREFIX = "x.";
|
|
2254
3644
|
manifestSession = (s, state2, world) => ({
|
|
2255
3645
|
slug: world.slug,
|
|
2256
3646
|
ref: world.ref,
|
|
3647
|
+
private: world.private,
|
|
2257
3648
|
versionId: state2.versionId,
|
|
2258
3649
|
sessionId: state2.sessionId,
|
|
2259
3650
|
ready: state2.ready,
|
|
2260
3651
|
state: state2.state,
|
|
2261
|
-
|
|
2262
|
-
...s.api ? {
|
|
2263
|
-
api: { url: s.api.url, ...s.api.token ? { token: s.api.token } : {} }
|
|
2264
|
-
} : {},
|
|
2265
|
-
...s.ui ? {
|
|
2266
|
-
ui: {
|
|
2267
|
-
url: s.ui.url,
|
|
2268
|
-
entry: uiEntryUrl(s.ui),
|
|
2269
|
-
apiPath: s.ui.apiPath ?? null
|
|
2270
|
-
}
|
|
2271
|
-
} : {},
|
|
2272
|
-
...s.browser ? { browser: { wsUrl: s.browser.wsUrl, viewport: s.browser.viewport } } : {}
|
|
3652
|
+
...surfaceDescriptor(s)
|
|
2273
3653
|
});
|
|
2274
3654
|
TaskSessions = class {
|
|
2275
3655
|
constructor(taskId, taskVersion, name, instruction, sessions2, worlds, hash = null) {
|
|
@@ -2288,10 +3668,10 @@ var init_taskSessions = __esm({
|
|
|
2288
3668
|
sessions;
|
|
2289
3669
|
worlds;
|
|
2290
3670
|
hash;
|
|
2291
|
-
/** This alias's
|
|
2292
|
-
*
|
|
3671
|
+
/** This alias's world as recorded at open/attach — what a `TaskRun`
|
|
3672
|
+
* filing needs to name, without exposing the whole map. */
|
|
2293
3673
|
worldRef(alias) {
|
|
2294
|
-
return this.worlds[alias] ?? { slug: "", ref: null };
|
|
3674
|
+
return this.worlds[alias] ?? { slug: "", ref: null, private: null };
|
|
2295
3675
|
}
|
|
2296
3676
|
/** The aliases, in the spec's order. */
|
|
2297
3677
|
get aliases() {
|
|
@@ -2448,8 +3828,51 @@ var init_evals = __esm({
|
|
|
2448
3828
|
}
|
|
2449
3829
|
});
|
|
2450
3830
|
|
|
3831
|
+
// src/tracing/prerequisites.ts
|
|
3832
|
+
function getEnv(key2) {
|
|
3833
|
+
const value = process.env[key2];
|
|
3834
|
+
return value ? value : void 0;
|
|
3835
|
+
}
|
|
3836
|
+
function isGatewayConfigured() {
|
|
3837
|
+
return !!(getEnv(GATEWAY_ENV.HOST) && getEnv(GATEWAY_ENV.PUBLIC_KEY) && getEnv(GATEWAY_ENV.SECRET_KEY));
|
|
3838
|
+
}
|
|
3839
|
+
var GATEWAY_ENV, OPENTELEMETRY_PEERS, MODULE_NOT_FOUND, OpenTelemetryMissing;
|
|
3840
|
+
var init_prerequisites = __esm({
|
|
3841
|
+
"src/tracing/prerequisites.ts"() {
|
|
3842
|
+
"use strict";
|
|
3843
|
+
GATEWAY_ENV = {
|
|
3844
|
+
HOST: "GATEWAY_HOST",
|
|
3845
|
+
PUBLIC_KEY: "GATEWAY_PUBLIC_KEY",
|
|
3846
|
+
SECRET_KEY: "GATEWAY_SECRET_KEY",
|
|
3847
|
+
ENDPOINT: "GATEWAY_OTLP_ENDPOINT"
|
|
3848
|
+
};
|
|
3849
|
+
OPENTELEMETRY_PEERS = [
|
|
3850
|
+
"@opentelemetry/api",
|
|
3851
|
+
"@opentelemetry/exporter-trace-otlp-http",
|
|
3852
|
+
"@opentelemetry/resources",
|
|
3853
|
+
"@opentelemetry/sdk-trace-base",
|
|
3854
|
+
"@opentelemetry/sdk-trace-node"
|
|
3855
|
+
];
|
|
3856
|
+
MODULE_NOT_FOUND = /* @__PURE__ */ new Set(["MODULE_NOT_FOUND", "ERR_MODULE_NOT_FOUND"]);
|
|
3857
|
+
OpenTelemetryMissing = class _OpenTelemetryMissing extends Error {
|
|
3858
|
+
constructor() {
|
|
3859
|
+
super(
|
|
3860
|
+
`OpenTelemetry packages not found. Install them with:
|
|
3861
|
+
npm install ${OPENTELEMETRY_PEERS.join(" ")}`
|
|
3862
|
+
);
|
|
3863
|
+
this.name = "OpenTelemetryMissing";
|
|
3864
|
+
}
|
|
3865
|
+
static explains(error) {
|
|
3866
|
+
if (error instanceof _OpenTelemetryMissing) return true;
|
|
3867
|
+
const { code, message } = error ?? {};
|
|
3868
|
+
return MODULE_NOT_FOUND.has(String(code)) && String(message).includes("@opentelemetry/");
|
|
3869
|
+
}
|
|
3870
|
+
};
|
|
3871
|
+
}
|
|
3872
|
+
});
|
|
3873
|
+
|
|
2451
3874
|
// src/tracing/identity.ts
|
|
2452
|
-
import { AsyncLocalStorage as
|
|
3875
|
+
import { AsyncLocalStorage as AsyncLocalStorage3 } from "async_hooks";
|
|
2453
3876
|
import { isSpanContextValid as isSpanContextValid2, trace as trace2 } from "@opentelemetry/api";
|
|
2454
3877
|
function resolveUserId() {
|
|
2455
3878
|
const contextual = currentUserStorage.getStore();
|
|
@@ -2502,7 +3925,7 @@ var init_identity = __esm({
|
|
|
2502
3925
|
"use strict";
|
|
2503
3926
|
init_users();
|
|
2504
3927
|
USER_ID_ATTRIBUTE = "gateway.user.id";
|
|
2505
|
-
currentUserStorage = new
|
|
3928
|
+
currentUserStorage = new AsyncLocalStorage3();
|
|
2506
3929
|
IdentitySpanProcessor = class {
|
|
2507
3930
|
onStart(span, _parentContext) {
|
|
2508
3931
|
const userId = resolveUserId();
|
|
@@ -2520,43 +3943,224 @@ var init_identity = __esm({
|
|
|
2520
3943
|
}
|
|
2521
3944
|
});
|
|
2522
3945
|
|
|
2523
|
-
// src/tracing/
|
|
2524
|
-
|
|
2525
|
-
|
|
2526
|
-
|
|
2527
|
-
|
|
2528
|
-
|
|
2529
|
-
|
|
2530
|
-
}
|
|
2531
|
-
|
|
2532
|
-
|
|
2533
|
-
return currentSessionStorage.getStore();
|
|
3946
|
+
// src/tracing/secrets.ts
|
|
3947
|
+
function jsonOrUndefined(text2) {
|
|
3948
|
+
let parsed;
|
|
3949
|
+
try {
|
|
3950
|
+
parsed = JSON.parse(text2);
|
|
3951
|
+
} catch {
|
|
3952
|
+
return void 0;
|
|
3953
|
+
}
|
|
3954
|
+
if (typeof parsed === "string") return parsed;
|
|
3955
|
+
return parsed !== null && typeof parsed === "object" ? parsed : void 0;
|
|
2534
3956
|
}
|
|
2535
|
-
function
|
|
2536
|
-
return
|
|
2537
|
-
|
|
2538
|
-
|
|
2539
|
-
|
|
3957
|
+
function encodings(value) {
|
|
3958
|
+
return [value, percentEncoded(value), JSON.stringify(value).slice(1, -1)];
|
|
3959
|
+
}
|
|
3960
|
+
function percentEncoded(value) {
|
|
3961
|
+
try {
|
|
3962
|
+
return encodeURIComponent(value);
|
|
3963
|
+
} catch {
|
|
3964
|
+
return value;
|
|
3965
|
+
}
|
|
3966
|
+
}
|
|
3967
|
+
function union(sets) {
|
|
3968
|
+
return new Set(sets.flatMap((set) => [...set]));
|
|
3969
|
+
}
|
|
3970
|
+
function leaves(value) {
|
|
3971
|
+
if (typeof value === "string") {
|
|
3972
|
+
return [...value].length >= MIN_SECRET_LENGTH ? /* @__PURE__ */ new Set([value]) : /* @__PURE__ */ new Set();
|
|
3973
|
+
}
|
|
3974
|
+
if (Array.isArray(value)) return union(value.map(leaves));
|
|
3975
|
+
if (value === null || typeof value !== "object") return /* @__PURE__ */ new Set();
|
|
3976
|
+
return union(Object.values(value).map(leaves));
|
|
3977
|
+
}
|
|
3978
|
+
function sameAttributes(before, after) {
|
|
3979
|
+
const keys = Object.keys(before);
|
|
3980
|
+
if (keys.length !== Object.keys(after).length) return false;
|
|
3981
|
+
return keys.every(
|
|
3982
|
+
(key2) => before[key2] === after[key2] || sameArray(before[key2], after[key2])
|
|
3983
|
+
);
|
|
3984
|
+
}
|
|
3985
|
+
function sameArray(before, after) {
|
|
3986
|
+
if (!Array.isArray(before) || !Array.isArray(after)) return false;
|
|
3987
|
+
return before.length === after.length && before.every((item, i) => item === after[i]);
|
|
3988
|
+
}
|
|
3989
|
+
function scrubbedRead(reads, property) {
|
|
3990
|
+
return typeof property === "string" && property in reads ? reads[property] : void 0;
|
|
3991
|
+
}
|
|
3992
|
+
function viewOf(span, reads) {
|
|
3993
|
+
const view = new Proxy(span, {
|
|
3994
|
+
get(target, property) {
|
|
3995
|
+
const read = scrubbedRead(reads, property);
|
|
3996
|
+
if (read) return read();
|
|
3997
|
+
const value = Reflect.get(target, property, target);
|
|
3998
|
+
if (typeof value !== "function") return value;
|
|
3999
|
+
return (...args) => {
|
|
4000
|
+
const result = value.apply(target, args);
|
|
4001
|
+
return result === target ? view : result;
|
|
4002
|
+
};
|
|
4003
|
+
},
|
|
4004
|
+
getOwnPropertyDescriptor(target, property) {
|
|
4005
|
+
const descriptor = Reflect.getOwnPropertyDescriptor(target, property);
|
|
4006
|
+
const read = scrubbedRead(reads, property);
|
|
4007
|
+
if (!read || !descriptor || !("value" in descriptor)) return descriptor;
|
|
4008
|
+
return { ...descriptor, value: read() };
|
|
4009
|
+
}
|
|
2540
4010
|
});
|
|
4011
|
+
return view;
|
|
2541
4012
|
}
|
|
2542
|
-
var
|
|
2543
|
-
var
|
|
2544
|
-
"src/tracing/
|
|
4013
|
+
var SECRET_KEYS, REDACTED2, MIN_SECRET_LENGTH, SpanSecrets, SPAN_SECRETS, SecretRedactingSpanProcessor;
|
|
4014
|
+
var init_secrets = __esm({
|
|
4015
|
+
"src/tracing/secrets.ts"() {
|
|
2545
4016
|
"use strict";
|
|
2546
|
-
|
|
2547
|
-
|
|
2548
|
-
|
|
2549
|
-
|
|
2550
|
-
|
|
2551
|
-
|
|
2552
|
-
|
|
4017
|
+
SECRET_KEYS = /* @__PURE__ */ new Set([
|
|
4018
|
+
"authorization_token",
|
|
4019
|
+
"authorizationToken"
|
|
4020
|
+
]);
|
|
4021
|
+
REDACTED2 = "[redacted: holds a credential]";
|
|
4022
|
+
MIN_SECRET_LENGTH = 8;
|
|
4023
|
+
SpanSecrets = class {
|
|
4024
|
+
constructor(keys = SECRET_KEYS) {
|
|
4025
|
+
this.keys = keys;
|
|
4026
|
+
}
|
|
4027
|
+
keys;
|
|
4028
|
+
isSecret(key2) {
|
|
4029
|
+
return this.keys.has(key2);
|
|
4030
|
+
}
|
|
4031
|
+
drops(attribute) {
|
|
4032
|
+
return this.mentions(attribute);
|
|
4033
|
+
}
|
|
4034
|
+
strip(value) {
|
|
4035
|
+
if (typeof value === "string") return this.stripNested(value);
|
|
4036
|
+
if (Array.isArray(value)) return value.map((item) => this.strip(item));
|
|
4037
|
+
if (value === null || typeof value !== "object") return value;
|
|
4038
|
+
return Object.fromEntries(
|
|
4039
|
+
Object.entries(value).filter(([key2]) => !this.isSecret(key2)).map(([key2, item]) => [key2, this.strip(item)])
|
|
4040
|
+
);
|
|
4041
|
+
}
|
|
4042
|
+
scrubAttribute(value) {
|
|
4043
|
+
try {
|
|
4044
|
+
return this.scrubbedValue(value);
|
|
4045
|
+
} catch {
|
|
4046
|
+
return Array.isArray(value) ? [REDACTED2] : REDACTED2;
|
|
2553
4047
|
}
|
|
2554
4048
|
}
|
|
2555
|
-
|
|
4049
|
+
scrubbedValue(value) {
|
|
4050
|
+
if (typeof value === "string") return this.scrubbedText(value);
|
|
4051
|
+
if (!Array.isArray(value)) return value;
|
|
4052
|
+
const results = value.map(
|
|
4053
|
+
(item) => typeof item === "string" ? this.cleaned(item) : { text: item, removed: /* @__PURE__ */ new Set() }
|
|
4054
|
+
);
|
|
4055
|
+
const removed = new Set(results.flatMap((r) => [...r.removed]));
|
|
4056
|
+
const scrubbed = results.map((r) => r.text);
|
|
4057
|
+
const withheld = scrubbed.some(
|
|
4058
|
+
(item) => typeof item === "string" && this.carries(item, removed)
|
|
4059
|
+
);
|
|
4060
|
+
return withheld ? [REDACTED2] : scrubbed;
|
|
2556
4061
|
}
|
|
2557
|
-
|
|
4062
|
+
scrubAttributes(attributes) {
|
|
4063
|
+
return Object.fromEntries(
|
|
4064
|
+
Object.entries(attributes).filter(([key2]) => !this.drops(key2)).map(([key2, value]) => [key2, this.scrubAttribute(value)])
|
|
4065
|
+
);
|
|
2558
4066
|
}
|
|
2559
|
-
|
|
4067
|
+
mentions(text2) {
|
|
4068
|
+
return [...this.keys].some((key2) => text2.includes(key2));
|
|
4069
|
+
}
|
|
4070
|
+
scrubbedText(text2) {
|
|
4071
|
+
const { text: cleaned, removed } = this.cleaned(text2);
|
|
4072
|
+
return this.carries(cleaned, removed) ? REDACTED2 : cleaned;
|
|
4073
|
+
}
|
|
4074
|
+
cleaned(text2) {
|
|
4075
|
+
if (!this.mentions(text2)) return { text: text2, removed: /* @__PURE__ */ new Set() };
|
|
4076
|
+
const parsed = jsonOrUndefined(text2);
|
|
4077
|
+
if (parsed === void 0) return { text: REDACTED2, removed: /* @__PURE__ */ new Set() };
|
|
4078
|
+
return {
|
|
4079
|
+
text: JSON.stringify(this.strip(parsed)),
|
|
4080
|
+
removed: this.removed(parsed)
|
|
4081
|
+
};
|
|
4082
|
+
}
|
|
4083
|
+
carries(text2, removed) {
|
|
4084
|
+
if (text2 === REDACTED2 || this.mentions(text2)) return true;
|
|
4085
|
+
return [...removed].some(
|
|
4086
|
+
(value) => encodings(value).some((form) => text2.includes(form))
|
|
4087
|
+
);
|
|
4088
|
+
}
|
|
4089
|
+
removed(value) {
|
|
4090
|
+
if (typeof value === "string") {
|
|
4091
|
+
const nested = this.mentions(value) ? jsonOrUndefined(value) : void 0;
|
|
4092
|
+
return nested === void 0 ? /* @__PURE__ */ new Set() : this.removed(nested);
|
|
4093
|
+
}
|
|
4094
|
+
if (Array.isArray(value)) return union(value.map((v) => this.removed(v)));
|
|
4095
|
+
if (value === null || typeof value !== "object") return /* @__PURE__ */ new Set();
|
|
4096
|
+
return union(
|
|
4097
|
+
Object.entries(value).map(
|
|
4098
|
+
([key2, item]) => this.isSecret(key2) ? leaves(item) : this.removed(item)
|
|
4099
|
+
)
|
|
4100
|
+
);
|
|
4101
|
+
}
|
|
4102
|
+
stripNested(text2) {
|
|
4103
|
+
if (!this.mentions(text2)) return text2;
|
|
4104
|
+
const parsed = jsonOrUndefined(text2);
|
|
4105
|
+
if (parsed === void 0) return text2;
|
|
4106
|
+
return JSON.stringify(this.strip(parsed));
|
|
4107
|
+
}
|
|
4108
|
+
};
|
|
4109
|
+
SPAN_SECRETS = new SpanSecrets();
|
|
4110
|
+
SecretRedactingSpanProcessor = class {
|
|
4111
|
+
constructor(inner, secrets = SPAN_SECRETS) {
|
|
4112
|
+
this.inner = inner;
|
|
4113
|
+
this.secrets = secrets;
|
|
4114
|
+
}
|
|
4115
|
+
inner;
|
|
4116
|
+
secrets;
|
|
4117
|
+
views = /* @__PURE__ */ new WeakMap();
|
|
4118
|
+
onStart(span, parentContext) {
|
|
4119
|
+
this.inner.onStart(this.viewFor(span), parentContext);
|
|
4120
|
+
}
|
|
4121
|
+
onEnd(span) {
|
|
4122
|
+
const view = this.viewFor(span);
|
|
4123
|
+
try {
|
|
4124
|
+
void [view.attributes, view.events, view.status];
|
|
4125
|
+
} catch (error) {
|
|
4126
|
+
console.warn(
|
|
4127
|
+
`[gatewaysdk.tracing] Dropped span "${span.name}": could not redact it: ${error?.name}`
|
|
4128
|
+
);
|
|
4129
|
+
return;
|
|
4130
|
+
}
|
|
4131
|
+
this.inner.onEnd(view);
|
|
4132
|
+
}
|
|
4133
|
+
viewFor(span) {
|
|
4134
|
+
const known = this.views.get(span);
|
|
4135
|
+
if (known) return known;
|
|
4136
|
+
const view = viewOf(span, {
|
|
4137
|
+
attributes: () => this.scrubbedAttributes(span.attributes),
|
|
4138
|
+
events: () => span.events.map((event) => this.scrubbedEvent(event)),
|
|
4139
|
+
status: () => this.scrubbedStatus(span.status)
|
|
4140
|
+
});
|
|
4141
|
+
this.views.set(span, view);
|
|
4142
|
+
return view;
|
|
4143
|
+
}
|
|
4144
|
+
forceFlush() {
|
|
4145
|
+
return this.inner.forceFlush();
|
|
4146
|
+
}
|
|
4147
|
+
shutdown() {
|
|
4148
|
+
return this.inner.shutdown();
|
|
4149
|
+
}
|
|
4150
|
+
scrubbedAttributes(attributes) {
|
|
4151
|
+
const clean = this.secrets.scrubAttributes(attributes);
|
|
4152
|
+
return sameAttributes(attributes, clean) ? attributes : clean;
|
|
4153
|
+
}
|
|
4154
|
+
scrubbedStatus(status) {
|
|
4155
|
+
if (!status.message) return status;
|
|
4156
|
+
const message = this.secrets.scrubAttribute(status.message);
|
|
4157
|
+
return message === status.message ? status : { ...status, message };
|
|
4158
|
+
}
|
|
4159
|
+
scrubbedEvent(event) {
|
|
4160
|
+
if (!event.attributes) return event;
|
|
4161
|
+
const attributes = this.scrubbedAttributes(event.attributes);
|
|
4162
|
+
if (attributes === event.attributes) return event;
|
|
4163
|
+
return { ...event, attributes };
|
|
2560
4164
|
}
|
|
2561
4165
|
};
|
|
2562
4166
|
}
|
|
@@ -2567,7 +4171,7 @@ var require_package = __commonJS({
|
|
|
2567
4171
|
"package.json"(exports, module) {
|
|
2568
4172
|
module.exports = {
|
|
2569
4173
|
name: "@withgateway/sdk",
|
|
2570
|
-
version: "0.
|
|
4174
|
+
version: "0.3.1",
|
|
2571
4175
|
description: "Gateway SDK for TypeScript - A/B experiments, tracing, and observability",
|
|
2572
4176
|
main: "./dist/index.js",
|
|
2573
4177
|
module: "./dist/index.mjs",
|
|
@@ -2767,7 +4371,7 @@ var require_package = __commonJS({
|
|
|
2767
4371
|
});
|
|
2768
4372
|
|
|
2769
4373
|
// src/build/index.ts
|
|
2770
|
-
import { createHash as
|
|
4374
|
+
import { createHash as createHash3 } from "crypto";
|
|
2771
4375
|
function canonicalJson(value) {
|
|
2772
4376
|
if (value === null || typeof value !== "object") {
|
|
2773
4377
|
return JSON.stringify(value);
|
|
@@ -2779,7 +4383,7 @@ function canonicalJson(value) {
|
|
|
2779
4383
|
return `{${entries.map(([k, v]) => `${JSON.stringify(k)}:${canonicalJson(v)}`).join(",")}}`;
|
|
2780
4384
|
}
|
|
2781
4385
|
function sha256(text2) {
|
|
2782
|
-
return `sha256:${
|
|
4386
|
+
return `sha256:${createHash3("sha256").update(text2).digest("hex")}`;
|
|
2783
4387
|
}
|
|
2784
4388
|
function captureSource() {
|
|
2785
4389
|
const stack = new Error().stack?.split("\n") ?? [];
|
|
@@ -3063,10 +4667,6 @@ __export(init_exports, {
|
|
|
3063
4667
|
isInitialized: () => isInitialized,
|
|
3064
4668
|
shutdown: () => shutdown2
|
|
3065
4669
|
});
|
|
3066
|
-
function getEnv(key2) {
|
|
3067
|
-
const value = process.env[key2];
|
|
3068
|
-
return value ? value : void 0;
|
|
3069
|
-
}
|
|
3070
4670
|
function log(message, ...args) {
|
|
3071
4671
|
if (state.debug) {
|
|
3072
4672
|
console.log(`[gatewaysdk.tracing] ${message}`, ...args);
|
|
@@ -3076,10 +4676,10 @@ function warn(message, ...args) {
|
|
|
3076
4676
|
console.warn(`[gatewaysdk.tracing] ${message}`, ...args);
|
|
3077
4677
|
}
|
|
3078
4678
|
function buildProvider(config, logFn) {
|
|
3079
|
-
const host = config.host ?? getEnv(
|
|
3080
|
-
const publicKey = config.publicKey ?? getEnv(
|
|
3081
|
-
const secretKey = config.secretKey ?? getEnv(
|
|
3082
|
-
const endpoint = config.endpoint ?? getEnv(
|
|
4679
|
+
const host = config.host ?? getEnv(GATEWAY_ENV.HOST);
|
|
4680
|
+
const publicKey = config.publicKey ?? getEnv(GATEWAY_ENV.PUBLIC_KEY);
|
|
4681
|
+
const secretKey = config.secretKey ?? getEnv(GATEWAY_ENV.SECRET_KEY);
|
|
4682
|
+
const endpoint = config.endpoint ?? getEnv(GATEWAY_ENV.ENDPOINT) ?? (host ? `${host.replace(/\/$/, "")}${DEFAULT_OTLP_PATH}` : void 0);
|
|
3083
4683
|
const missing = [];
|
|
3084
4684
|
if (!host) missing.push("host (or GATEWAY_HOST env var)");
|
|
3085
4685
|
if (!publicKey) missing.push("publicKey (or GATEWAY_PUBLIC_KEY env var)");
|
|
@@ -3116,9 +4716,7 @@ function buildProvider(config, logFn) {
|
|
|
3116
4716
|
ATTR_SERVICE_NAME = "service.name";
|
|
3117
4717
|
}
|
|
3118
4718
|
} catch {
|
|
3119
|
-
throw new
|
|
3120
|
-
"OpenTelemetry packages not found. Install them with:\nnpm install @opentelemetry/sdk-trace-node @opentelemetry/sdk-trace-base @opentelemetry/exporter-trace-otlp-http @opentelemetry/resources"
|
|
3121
|
-
);
|
|
4719
|
+
throw new OpenTelemetryMissing();
|
|
3122
4720
|
}
|
|
3123
4721
|
const resourceAttrs = {
|
|
3124
4722
|
[ATTR_SERVICE_NAME]: config.serviceName ?? "gatewaysdk-tracing"
|
|
@@ -3174,7 +4772,7 @@ function buildProvider(config, logFn) {
|
|
|
3174
4772
|
const spanProcessors = [];
|
|
3175
4773
|
if (config.customSpanProcessors) {
|
|
3176
4774
|
for (const sp of config.customSpanProcessors) {
|
|
3177
|
-
spanProcessors.push(sp);
|
|
4775
|
+
spanProcessors.push(new SecretRedactingSpanProcessor(sp));
|
|
3178
4776
|
logFn(
|
|
3179
4777
|
"Added custom span processor: %s",
|
|
3180
4778
|
sp.constructor?.name ?? "unknown"
|
|
@@ -3193,7 +4791,11 @@ function buildProvider(config, logFn) {
|
|
|
3193
4791
|
if (config.batch?.maxExportBatchSize) {
|
|
3194
4792
|
batchConfig.maxExportBatchSize = config.batch.maxExportBatchSize;
|
|
3195
4793
|
}
|
|
3196
|
-
spanProcessors.push(
|
|
4794
|
+
spanProcessors.push(
|
|
4795
|
+
new SecretRedactingSpanProcessor(
|
|
4796
|
+
new BatchSpanProcessor(exporter, batchConfig)
|
|
4797
|
+
)
|
|
4798
|
+
);
|
|
3197
4799
|
let provider = new NodeTracerProvider({
|
|
3198
4800
|
resource: createResource(resourceAttrs)
|
|
3199
4801
|
});
|
|
@@ -3320,26 +4922,17 @@ async function shutdown2() {
|
|
|
3320
4922
|
function isInitialized() {
|
|
3321
4923
|
return state.initialized;
|
|
3322
4924
|
}
|
|
3323
|
-
|
|
3324
|
-
const host = getEnv(ENV_VARS.HOST);
|
|
3325
|
-
const publicKey = getEnv(ENV_VARS.PUBLIC_KEY);
|
|
3326
|
-
const secretKey = getEnv(ENV_VARS.SECRET_KEY);
|
|
3327
|
-
return !!(host && publicKey && secretKey);
|
|
3328
|
-
}
|
|
3329
|
-
var ENV_VARS, DEFAULT_OTLP_PATH, state;
|
|
4925
|
+
var DEFAULT_OTLP_PATH, state;
|
|
3330
4926
|
var init_init = __esm({
|
|
3331
4927
|
"src/tracing/init.ts"() {
|
|
3332
4928
|
"use strict";
|
|
3333
4929
|
init_identity();
|
|
3334
|
-
|
|
4930
|
+
init_secrets();
|
|
4931
|
+
init_session();
|
|
3335
4932
|
init_scores();
|
|
3336
4933
|
init_build();
|
|
3337
|
-
|
|
3338
|
-
|
|
3339
|
-
PUBLIC_KEY: "GATEWAY_PUBLIC_KEY",
|
|
3340
|
-
SECRET_KEY: "GATEWAY_SECRET_KEY",
|
|
3341
|
-
ENDPOINT: "GATEWAY_OTLP_ENDPOINT"
|
|
3342
|
-
};
|
|
4934
|
+
init_prerequisites();
|
|
4935
|
+
init_prerequisites();
|
|
3343
4936
|
DEFAULT_OTLP_PATH = "/api/public/otel/v1/traces";
|
|
3344
4937
|
state = {
|
|
3345
4938
|
initialized: false,
|
|
@@ -3348,6 +4941,45 @@ var init_init = __esm({
|
|
|
3348
4941
|
}
|
|
3349
4942
|
});
|
|
3350
4943
|
|
|
4944
|
+
// src/worlds/taskTracing.ts
|
|
4945
|
+
var TaskTracing;
|
|
4946
|
+
var init_taskTracing = __esm({
|
|
4947
|
+
"src/worlds/taskTracing.ts"() {
|
|
4948
|
+
"use strict";
|
|
4949
|
+
init_prerequisites();
|
|
4950
|
+
TaskTracing = class _TaskTracing {
|
|
4951
|
+
constructor(load = () => Promise.resolve().then(() => (init_init(), init_exports))) {
|
|
4952
|
+
this.load = load;
|
|
4953
|
+
}
|
|
4954
|
+
load;
|
|
4955
|
+
static warned = false;
|
|
4956
|
+
async start(requested) {
|
|
4957
|
+
if (!requested || !isGatewayConfigured()) return false;
|
|
4958
|
+
try {
|
|
4959
|
+
(await this.load()).init();
|
|
4960
|
+
return true;
|
|
4961
|
+
} catch (error) {
|
|
4962
|
+
_TaskTracing.warnOnce(error);
|
|
4963
|
+
return false;
|
|
4964
|
+
}
|
|
4965
|
+
}
|
|
4966
|
+
static warnOnce(error) {
|
|
4967
|
+
if (_TaskTracing.warned) return;
|
|
4968
|
+
_TaskTracing.warned = true;
|
|
4969
|
+
console.warn(
|
|
4970
|
+
`[gatewaysdk.tracing] Task runs in this process are not traced. ${_TaskTracing.reason(error)}
|
|
4971
|
+
Pass --no-trace (trace: false) to run untraced without this warning.`
|
|
4972
|
+
);
|
|
4973
|
+
}
|
|
4974
|
+
static reason(error) {
|
|
4975
|
+
if (OpenTelemetryMissing.explains(error))
|
|
4976
|
+
return new OpenTelemetryMissing().message;
|
|
4977
|
+
return error instanceof Error ? error.message : String(error);
|
|
4978
|
+
}
|
|
4979
|
+
};
|
|
4980
|
+
}
|
|
4981
|
+
});
|
|
4982
|
+
|
|
3351
4983
|
// src/worlds/taskRun.ts
|
|
3352
4984
|
import { randomBytes } from "crypto";
|
|
3353
4985
|
import * as fs from "fs";
|
|
@@ -3463,18 +5095,7 @@ async function runTask(ref, agent, opts) {
|
|
|
3463
5095
|
const started = Date.now();
|
|
3464
5096
|
try {
|
|
3465
5097
|
await live.ready();
|
|
3466
|
-
|
|
3467
|
-
if (opts.trace !== false) {
|
|
3468
|
-
try {
|
|
3469
|
-
const { isGatewayConfigured: isGatewayConfigured2, init: init3 } = await Promise.resolve().then(() => (init_init(), init_exports));
|
|
3470
|
-
if (isGatewayConfigured2()) {
|
|
3471
|
-
init3();
|
|
3472
|
-
traced = true;
|
|
3473
|
-
}
|
|
3474
|
-
} catch {
|
|
3475
|
-
traced = false;
|
|
3476
|
-
}
|
|
3477
|
-
}
|
|
5098
|
+
const traced = await new TaskTracing().start(opts.trace !== false);
|
|
3478
5099
|
const taskRun = new TaskRun(
|
|
3479
5100
|
runId,
|
|
3480
5101
|
live.instruction ?? "",
|
|
@@ -3487,7 +5108,7 @@ async function runTask(ref, agent, opts) {
|
|
|
3487
5108
|
let extra = {};
|
|
3488
5109
|
try {
|
|
3489
5110
|
const invoke = () => agent(taskRun);
|
|
3490
|
-
const result = traced ? await (await Promise.resolve().then(() => (
|
|
5111
|
+
const result = traced ? await (await Promise.resolve().then(() => (init_session(), session_exports))).withSession(runId, invoke) : await invoke();
|
|
3491
5112
|
({ report, extra } = reportFromResult(result));
|
|
3492
5113
|
} catch (error) {
|
|
3493
5114
|
const message = (error instanceof Error ? error.message : String(error)) || "Unknown error";
|
|
@@ -3560,8 +5181,9 @@ var init_taskRun = __esm({
|
|
|
3560
5181
|
"use strict";
|
|
3561
5182
|
init_browser();
|
|
3562
5183
|
init_evals();
|
|
3563
|
-
|
|
5184
|
+
init_session2();
|
|
3564
5185
|
init_taskSessions();
|
|
5186
|
+
init_taskTracing();
|
|
3565
5187
|
TaskRun = class {
|
|
3566
5188
|
constructor(runId, instruction, model, sessions2, manifest) {
|
|
3567
5189
|
this.runId = runId;
|
|
@@ -3765,6 +5387,52 @@ var init_setRun = __esm({
|
|
|
3765
5387
|
}
|
|
3766
5388
|
});
|
|
3767
5389
|
|
|
5390
|
+
// src/worlds/requestLog.ts
|
|
5391
|
+
var WorldRequestLog;
|
|
5392
|
+
var init_requestLog = __esm({
|
|
5393
|
+
"src/worlds/requestLog.ts"() {
|
|
5394
|
+
"use strict";
|
|
5395
|
+
WorldRequestLog = class _WorldRequestLog {
|
|
5396
|
+
constructor(requests) {
|
|
5397
|
+
this.requests = requests;
|
|
5398
|
+
}
|
|
5399
|
+
requests;
|
|
5400
|
+
static async read(session) {
|
|
5401
|
+
const state2 = await session.state();
|
|
5402
|
+
const calls = state2?.calls;
|
|
5403
|
+
if (!Array.isArray(calls)) return null;
|
|
5404
|
+
return new _WorldRequestLog(calls.filter((c) => typeof c === "object" && c !== null));
|
|
5405
|
+
}
|
|
5406
|
+
/** How many older requests the world no longer keeps (its log is bounded): the gap
|
|
5407
|
+
* before the first entry it still holds. */
|
|
5408
|
+
get dropped() {
|
|
5409
|
+
const first = Number(this.requests[0]?.seq) || 1;
|
|
5410
|
+
return Math.max(0, first - 1);
|
|
5411
|
+
}
|
|
5412
|
+
/** Each request in the shape of a ledger line, `kind: "request"`, so one JSONL
|
|
5413
|
+
* file holds both. */
|
|
5414
|
+
asCalls() {
|
|
5415
|
+
return this.requests.map((r) => ({
|
|
5416
|
+
seq: Number(r.seq) || 0,
|
|
5417
|
+
kind: "request",
|
|
5418
|
+
tool: r.operation ?? null,
|
|
5419
|
+
args: {
|
|
5420
|
+
method: r.method ?? null,
|
|
5421
|
+
path: r.path ?? null,
|
|
5422
|
+
args: r.args ?? null,
|
|
5423
|
+
query: r.query ?? null,
|
|
5424
|
+
body: r.body ?? null,
|
|
5425
|
+
via: r.via ?? null
|
|
5426
|
+
},
|
|
5427
|
+
result: { status: r.status ?? null, rows: r.rows ?? null, found: r.found ?? null },
|
|
5428
|
+
error: null,
|
|
5429
|
+
completedAt: r.at ?? null
|
|
5430
|
+
}));
|
|
5431
|
+
}
|
|
5432
|
+
};
|
|
5433
|
+
}
|
|
5434
|
+
});
|
|
5435
|
+
|
|
3768
5436
|
// src/worlds/checkoutTarget.ts
|
|
3769
5437
|
import * as fs2 from "fs";
|
|
3770
5438
|
import * as path2 from "path";
|
|
@@ -3869,7 +5537,7 @@ var init_checkoutTarget = __esm({
|
|
|
3869
5537
|
});
|
|
3870
5538
|
|
|
3871
5539
|
// src/worlds/worldDir.ts
|
|
3872
|
-
import { createHash as
|
|
5540
|
+
import { createHash as createHash4 } from "crypto";
|
|
3873
5541
|
import * as fs3 from "fs";
|
|
3874
5542
|
import * as path3 from "path";
|
|
3875
5543
|
var WORLD_MANIFEST, API_BUNDLE_MANIFEST, BUNDLED_WORLD_PREFIX, CONNECTOR_SPEC, PYPROJECT, BENCHMARK_CONFIG, WORLD_SCHEMA_MARKERS, WORLD_ROOT_MARKERS, BROAD_ROOT_MARKERS, SKIPPED_DIRS, V1_DEP, V1_IMPORT, V1_TASKSET, HARBOR_TASK, skippedDir, byCodePoint, WorldDir;
|
|
@@ -3979,7 +5647,7 @@ var init_worldDir = __esm({
|
|
|
3979
5647
|
* sorted order: the version's identity, byte-compatible with
|
|
3980
5648
|
* `_archive.compute_content_hash` and Prime Intellect. */
|
|
3981
5649
|
get contentHash() {
|
|
3982
|
-
const hasher =
|
|
5650
|
+
const hasher = createHash4("sha256");
|
|
3983
5651
|
for (const rel of this.archivePaths) {
|
|
3984
5652
|
hasher.update(Buffer.from(`file:${rel}`, "utf-8"));
|
|
3985
5653
|
hasher.update(fs3.readFileSync(path3.join(this.dir, rel)));
|
|
@@ -4175,7 +5843,7 @@ __export(hub_exports, {
|
|
|
4175
5843
|
snapshotTreeHashes: () => snapshotTreeHashes,
|
|
4176
5844
|
writeLocalMeta: () => writeLocalMeta
|
|
4177
5845
|
});
|
|
4178
|
-
import { createHash as
|
|
5846
|
+
import { createHash as createHash5 } from "crypto";
|
|
4179
5847
|
import { gzipSync } from "zlib";
|
|
4180
5848
|
import * as fs5 from "fs";
|
|
4181
5849
|
import * as path5 from "path";
|
|
@@ -4287,7 +5955,7 @@ function writeLocalMeta(dir, meta) {
|
|
|
4287
5955
|
function snapshotTreeHashes(dir) {
|
|
4288
5956
|
const out = {};
|
|
4289
5957
|
for (const relPath of collectArchiveRelPaths(dir)) {
|
|
4290
|
-
out[relPath] =
|
|
5958
|
+
out[relPath] = createHash5("sha256").update(fs5.readFileSync(path5.join(dir, relPath))).digest("hex");
|
|
4291
5959
|
}
|
|
4292
5960
|
return out;
|
|
4293
5961
|
}
|
|
@@ -4333,7 +6001,7 @@ function buildFileManifest(dir) {
|
|
|
4333
6001
|
path: relPath,
|
|
4334
6002
|
isDirectory: false,
|
|
4335
6003
|
size: payload.length,
|
|
4336
|
-
sha256:
|
|
6004
|
+
sha256: createHash5("sha256").update(payload).digest("hex")
|
|
4337
6005
|
};
|
|
4338
6006
|
});
|
|
4339
6007
|
}
|
|
@@ -4558,7 +6226,7 @@ var init_hub = __esm({
|
|
|
4558
6226
|
tracked;
|
|
4559
6227
|
declared;
|
|
4560
6228
|
};
|
|
4561
|
-
sha256b64 = (data) =>
|
|
6229
|
+
sha256b64 = (data) => createHash5("sha256").update(data).digest("base64");
|
|
4562
6230
|
DetachedPushError = class extends Error {
|
|
4563
6231
|
constructor(dir, tag) {
|
|
4564
6232
|
super(
|
|
@@ -5185,7 +6853,7 @@ var init_json = __esm({
|
|
|
5185
6853
|
});
|
|
5186
6854
|
|
|
5187
6855
|
// src/worlds/transforms.ts
|
|
5188
|
-
import { createHash as
|
|
6856
|
+
import { createHash as createHash6 } from "crypto";
|
|
5189
6857
|
function parseTransform(name) {
|
|
5190
6858
|
const simple = Object.prototype.hasOwnProperty.call(SIMPLE, name) ? SIMPLE[name] : void 0;
|
|
5191
6859
|
if (simple) return simple;
|
|
@@ -5223,7 +6891,7 @@ var init_transforms = __esm({
|
|
|
5223
6891
|
return at === -1 ? "" : value.slice(at + 1).toLowerCase();
|
|
5224
6892
|
};
|
|
5225
6893
|
stripPrefix = (prefix) => (value) => value.startsWith(prefix) ? value.slice(prefix.length) : value;
|
|
5226
|
-
hex = (algorithm, value) =>
|
|
6894
|
+
hex = (algorithm, value) => createHash6(algorithm).update(value, "utf8").digest("hex");
|
|
5227
6895
|
SIMPLE = {
|
|
5228
6896
|
lower: (value) => value.toLowerCase(),
|
|
5229
6897
|
upper: (value) => value.toUpperCase(),
|
|
@@ -5247,7 +6915,7 @@ var init_transforms = __esm({
|
|
|
5247
6915
|
});
|
|
5248
6916
|
|
|
5249
6917
|
// src/worlds/redaction.ts
|
|
5250
|
-
import { createHash as
|
|
6918
|
+
import { createHash as createHash7 } from "crypto";
|
|
5251
6919
|
function pyText(value) {
|
|
5252
6920
|
if (typeof value === "string") return value;
|
|
5253
6921
|
if (Number.isInteger(value)) return String(value);
|
|
@@ -5256,7 +6924,7 @@ function pyText(value) {
|
|
|
5256
6924
|
return pyFloatRepr(value);
|
|
5257
6925
|
}
|
|
5258
6926
|
function hashForm(slug, plaintext) {
|
|
5259
|
-
return "sha256:" +
|
|
6927
|
+
return "sha256:" + createHash7("sha256").update(`${slug}:${pyText(plaintext)}`, "utf8").digest("hex");
|
|
5260
6928
|
}
|
|
5261
6929
|
function preserveForm(slug, plaintext) {
|
|
5262
6930
|
const kind = typeof plaintext === "string" ? "str" : isInt(plaintext) ? "int" : "float";
|
|
@@ -5265,12 +6933,12 @@ function preserveForm(slug, plaintext) {
|
|
|
5265
6933
|
}
|
|
5266
6934
|
function shapeText(slug, text2, kind) {
|
|
5267
6935
|
const seed = Buffer.from(`${slug}:${text2}`, "utf8");
|
|
5268
|
-
let digest =
|
|
6936
|
+
let digest = createHash7("sha256").update(seed).digest();
|
|
5269
6937
|
let cursor = 0;
|
|
5270
6938
|
const out = [];
|
|
5271
6939
|
for (const char of text2) {
|
|
5272
6940
|
if (cursor === digest.length) {
|
|
5273
|
-
digest =
|
|
6941
|
+
digest = createHash7("sha256").update(Buffer.concat([digest, seed])).digest();
|
|
5274
6942
|
cursor = 0;
|
|
5275
6943
|
}
|
|
5276
6944
|
const byte = digest[cursor];
|
|
@@ -5598,13 +7266,14 @@ async function localBridge(request, local, opts = {}) {
|
|
|
5598
7266
|
child.stdin.end(input);
|
|
5599
7267
|
});
|
|
5600
7268
|
}
|
|
5601
|
-
var MIN_PYTHON, DIAGNOSTIC_TAIL, BRIDGE_BOOTSTRAP, pythonCache, pythonProbes, PYTHON_CANDIDATES, UV_FIND;
|
|
7269
|
+
var MIN_PYTHON, MIN_PYTHON_LABEL, DIAGNOSTIC_TAIL, BRIDGE_BOOTSTRAP, pythonCache, pythonProbes, PYTHON_CANDIDATES, UV_FIND;
|
|
5602
7270
|
var init_local = __esm({
|
|
5603
7271
|
"src/cli/runtime/local.ts"() {
|
|
5604
7272
|
"use strict";
|
|
5605
7273
|
init_router();
|
|
5606
7274
|
init_config();
|
|
5607
7275
|
MIN_PYTHON = [3, 12];
|
|
7276
|
+
MIN_PYTHON_LABEL = MIN_PYTHON.join(".");
|
|
5608
7277
|
DIAGNOSTIC_TAIL = 600;
|
|
5609
7278
|
BRIDGE_BOOTSTRAP = `import sys,runpy,types,os
|
|
5610
7279
|
root=sys.argv[1]
|
|
@@ -6169,7 +7838,7 @@ if (fn) {
|
|
|
6169
7838
|
});
|
|
6170
7839
|
|
|
6171
7840
|
// src/cli/platform/worldData/batches.ts
|
|
6172
|
-
import { createHash as
|
|
7841
|
+
import { createHash as createHash8 } from "crypto";
|
|
6173
7842
|
import * as fs11 from "fs";
|
|
6174
7843
|
function isSettled(status) {
|
|
6175
7844
|
if (!TERMINAL_STATES.has(status.state)) return false;
|
|
@@ -6180,7 +7849,7 @@ function uploadHeadersFor(gz) {
|
|
|
6180
7849
|
return {
|
|
6181
7850
|
"content-type": "application/gzip",
|
|
6182
7851
|
"content-length": String(gz.length),
|
|
6183
|
-
"x-amz-checksum-sha256":
|
|
7852
|
+
"x-amz-checksum-sha256": createHash8("sha256").update(gz).digest("base64")
|
|
6184
7853
|
};
|
|
6185
7854
|
}
|
|
6186
7855
|
async function forEachLimited(items, limit, fn) {
|
|
@@ -6383,7 +8052,7 @@ var init_batches = __esm({
|
|
|
6383
8052
|
});
|
|
6384
8053
|
|
|
6385
8054
|
// src/cli/platform/worldData/chunker.ts
|
|
6386
|
-
import { createHash as
|
|
8055
|
+
import { createHash as createHash9 } from "crypto";
|
|
6387
8056
|
import { deflateRawSync } from "zlib";
|
|
6388
8057
|
function chunkLine(row, declared) {
|
|
6389
8058
|
if (declared !== null) return dumps(row.row) + "\n";
|
|
@@ -6424,12 +8093,12 @@ function finishChunk(ordinal, raw, rows, entity, firstRow = 0) {
|
|
|
6424
8093
|
const gz = gzipDeterministic(raw, { name: chunkName(ordinal) });
|
|
6425
8094
|
return {
|
|
6426
8095
|
ordinal,
|
|
6427
|
-
digest:
|
|
8096
|
+
digest: createHash9("sha256").update(gz).digest("hex"),
|
|
6428
8097
|
bytes: gz.length,
|
|
6429
8098
|
rows,
|
|
6430
8099
|
entity,
|
|
6431
8100
|
rawBytes: raw.length,
|
|
6432
|
-
contentSha256:
|
|
8101
|
+
contentSha256: createHash9("sha256").update(raw).digest("hex"),
|
|
6433
8102
|
firstRow,
|
|
6434
8103
|
gz
|
|
6435
8104
|
};
|
|
@@ -6766,7 +8435,7 @@ var init_ingest = __esm({
|
|
|
6766
8435
|
});
|
|
6767
8436
|
|
|
6768
8437
|
// src/worlds/editSessions.ts
|
|
6769
|
-
var WORLDS, WorldEditClient;
|
|
8438
|
+
var WORLDS, WorldEditClient, TASK_EDITS, TaskEditClient;
|
|
6770
8439
|
var init_editSessions = __esm({
|
|
6771
8440
|
"src/worlds/editSessions.ts"() {
|
|
6772
8441
|
"use strict";
|
|
@@ -6798,6 +8467,22 @@ var init_editSessions = __esm({
|
|
|
6798
8467
|
return apiRequest(this.options, "POST", `${WORLDS}/${encodeURIComponent(slug)}/edits/rollback`, input);
|
|
6799
8468
|
}
|
|
6800
8469
|
};
|
|
8470
|
+
TASK_EDITS = "/api/public/world-task-edits";
|
|
8471
|
+
TaskEditClient = class {
|
|
8472
|
+
constructor(options = {}) {
|
|
8473
|
+
this.options = options;
|
|
8474
|
+
}
|
|
8475
|
+
options;
|
|
8476
|
+
status(task) {
|
|
8477
|
+
return apiRequest(this.options, "POST", `${TASK_EDITS}/status`, { task });
|
|
8478
|
+
}
|
|
8479
|
+
close(task, input = {}) {
|
|
8480
|
+
return apiRequest(this.options, "POST", `${TASK_EDITS}/close`, { task, ...input });
|
|
8481
|
+
}
|
|
8482
|
+
rollback(task, input) {
|
|
8483
|
+
return apiRequest(this.options, "POST", `${TASK_EDITS}/rollback`, { task, ...input });
|
|
8484
|
+
}
|
|
8485
|
+
};
|
|
6801
8486
|
}
|
|
6802
8487
|
});
|
|
6803
8488
|
|
|
@@ -6893,6 +8578,10 @@ var init_dryRun = __esm({
|
|
|
6893
8578
|
// src/worlds/index.ts
|
|
6894
8579
|
var worlds_exports = {};
|
|
6895
8580
|
__export(worlds_exports, {
|
|
8581
|
+
ACTION_NAMES: () => ACTION_NAMES,
|
|
8582
|
+
ActionTracer: () => ActionTracer,
|
|
8583
|
+
AnthropicComputer: () => AnthropicComputer,
|
|
8584
|
+
AnthropicComputer20251124: () => AnthropicComputer20251124,
|
|
6896
8585
|
ApiError: () => ApiError,
|
|
6897
8586
|
BROWSER_GONE_PATTERNS: () => BROWSER_GONE_PATTERNS,
|
|
6898
8587
|
BROWSER_TIERS: () => BROWSER_TIERS,
|
|
@@ -6904,11 +8593,13 @@ __export(worlds_exports, {
|
|
|
6904
8593
|
CALL_BODY_LIMIT_LABEL: () => CALL_BODY_LIMIT_LABEL,
|
|
6905
8594
|
COMPUTER_USE_SPECS: () => COMPUTER_USE_SPECS,
|
|
6906
8595
|
CheckoutProvenance: () => CheckoutProvenance,
|
|
8596
|
+
ComputerAction: () => ComputerAction,
|
|
6907
8597
|
DEFAULT_BRANCH: () => DEFAULT_BRANCH,
|
|
6908
8598
|
DEFAULT_VIEWPORT: () => DEFAULT_VIEWPORT,
|
|
6909
8599
|
DRY_RUN_AGENT: () => DRY_RUN_AGENT,
|
|
6910
8600
|
DRY_RUN_KIND: () => DRY_RUN_KIND,
|
|
6911
8601
|
DetachedPushError: () => DetachedPushError,
|
|
8602
|
+
Display: () => Display,
|
|
6912
8603
|
DryRunOutcome: () => DryRunOutcome,
|
|
6913
8604
|
EVENT_BATCH_SIZE: () => EVENT_BATCH_SIZE,
|
|
6914
8605
|
EVENT_FLUSH_INTERVAL_MS: () => EVENT_FLUSH_INTERVAL_MS,
|
|
@@ -6918,19 +8609,30 @@ __export(worlds_exports, {
|
|
|
6918
8609
|
GatewayEvalsClient: () => GatewayEvalsClient,
|
|
6919
8610
|
HostedDryRunClient: () => HostedDryRunClient,
|
|
6920
8611
|
IDLE_WARNING_MINUTES: () => IDLE_WARNING_MINUTES,
|
|
8612
|
+
KEY_NAMES: () => KEY_NAMES,
|
|
8613
|
+
KeyChord: () => KeyChord,
|
|
8614
|
+
NOT_EXECUTED: () => NOT_EXECUTED,
|
|
6921
8615
|
NO_GRADER_REASON: () => NO_GRADER_REASON,
|
|
8616
|
+
NativeComputer: () => NativeComputer,
|
|
8617
|
+
OpenAIComputer: () => OpenAIComputer,
|
|
8618
|
+
OpenAIPreviewComputer: () => OpenAIPreviewComputer,
|
|
6922
8619
|
PLATFORM_TIMEOUT_DEFAULT_MS: () => PLATFORM_TIMEOUT_DEFAULT_MS,
|
|
6923
8620
|
PLATFORM_TIMEOUT_ENV: () => PLATFORM_TIMEOUT_ENV,
|
|
8621
|
+
PendingSafetyChecks: () => PendingSafetyChecks,
|
|
6924
8622
|
PlatformTransport: () => PlatformTransport,
|
|
6925
8623
|
PushSlugConflict: () => PushSlugConflict,
|
|
6926
8624
|
RECOVER_BUDGET_MS: () => RECOVER_BUDGET_MS,
|
|
6927
8625
|
SANDBOX_REQUEST_TIMEOUT_MS: () => SANDBOX_REQUEST_TIMEOUT_MS,
|
|
8626
|
+
SECRET_KEY: () => SECRET_KEY,
|
|
6928
8627
|
SESSION_STATES: () => SESSION_STATES,
|
|
8628
|
+
SPAN_PREFIX: () => SPAN_PREFIX,
|
|
6929
8629
|
STATUS_WAIT_CAP_SECONDS: () => STATUS_WAIT_CAP_SECONDS,
|
|
6930
8630
|
STRIP_PREFIX: () => STRIP_PREFIX,
|
|
6931
8631
|
SURFACE_KINDS: () => SURFACE_KINDS,
|
|
8632
|
+
Screen: () => Screen,
|
|
6932
8633
|
SecretScrubber: () => SecretScrubber,
|
|
6933
8634
|
TRANSFORMS: () => TRANSFORMS,
|
|
8635
|
+
TaskEditClient: () => TaskEditClient,
|
|
6934
8636
|
TaskRun: () => TaskRun,
|
|
6935
8637
|
TaskSessions: () => TaskSessions,
|
|
6936
8638
|
TransportCause: () => TransportCause,
|
|
@@ -6940,6 +8642,7 @@ __export(worlds_exports, {
|
|
|
6940
8642
|
WorldBrowser: () => WorldBrowser,
|
|
6941
8643
|
WorldCallTooLarge: () => WorldCallTooLarge,
|
|
6942
8644
|
WorldEditClient: () => WorldEditClient,
|
|
8645
|
+
WorldRequestLog: () => WorldRequestLog,
|
|
6943
8646
|
WorldSandboxClient: () => WorldSandboxClient,
|
|
6944
8647
|
WorldSession: () => WorldSession,
|
|
6945
8648
|
WorldSessionCallError: () => WorldSessionCallError,
|
|
@@ -7003,6 +8706,7 @@ __export(worlds_exports, {
|
|
|
7003
8706
|
parseTransform: () => parseTransform,
|
|
7004
8707
|
parseWorldTaskRefs: () => parseWorldTaskRefs,
|
|
7005
8708
|
platformTimeoutMs: () => platformTimeoutMs,
|
|
8709
|
+
playwrightKey: () => playwrightKey,
|
|
7006
8710
|
preserveForm: () => preserveForm,
|
|
7007
8711
|
propose: () => propose,
|
|
7008
8712
|
pull: () => pull,
|
|
@@ -7012,6 +8716,7 @@ __export(worlds_exports, {
|
|
|
7012
8716
|
pyText: () => pyText,
|
|
7013
8717
|
queryRows: () => queryRows,
|
|
7014
8718
|
queryRowsSearch: () => queryRowsSearch,
|
|
8719
|
+
readField: () => readField,
|
|
7015
8720
|
readLocalMeta: () => readLocalMeta,
|
|
7016
8721
|
readToolCallRecords: () => readToolCallRecords,
|
|
7017
8722
|
rebaseConflicts: () => rebaseConflicts,
|
|
@@ -7031,6 +8736,7 @@ __export(worlds_exports, {
|
|
|
7031
8736
|
shapeText: () => shapeText,
|
|
7032
8737
|
snapshotTreeHashes: () => snapshotTreeHashes,
|
|
7033
8738
|
storedForms: () => storedForms,
|
|
8739
|
+
surfaceDescriptor: () => surfaceDescriptor,
|
|
7034
8740
|
surfaceKinds: () => surfaceKinds,
|
|
7035
8741
|
taskLabel: () => taskLabel,
|
|
7036
8742
|
toolCallRecordsIn: () => toolCallRecordsIn,
|
|
@@ -7261,7 +8967,7 @@ var init_worlds = __esm({
|
|
|
7261
8967
|
"use strict";
|
|
7262
8968
|
init_transport();
|
|
7263
8969
|
init_transport();
|
|
7264
|
-
|
|
8970
|
+
init_session2();
|
|
7265
8971
|
init_sessionList();
|
|
7266
8972
|
init_sessionContract();
|
|
7267
8973
|
init_taskRef();
|
|
@@ -7272,7 +8978,10 @@ var init_worlds = __esm({
|
|
|
7272
8978
|
init_checkoutProvenance();
|
|
7273
8979
|
init_evals();
|
|
7274
8980
|
init_browser();
|
|
8981
|
+
init_surfaceDescriptor();
|
|
8982
|
+
init_requestLog();
|
|
7275
8983
|
init_browserReconnect();
|
|
8984
|
+
init_nativeComputer();
|
|
7276
8985
|
init_hub();
|
|
7277
8986
|
init_validate();
|
|
7278
8987
|
init_describe();
|
|
@@ -7339,7 +9048,7 @@ var init_worlds = __esm({
|
|
|
7339
9048
|
* worlds/session.ts.
|
|
7340
9049
|
*/
|
|
7341
9050
|
async open(task, opts = {}) {
|
|
7342
|
-
const { openSession: openSession2 } = await Promise.resolve().then(() => (
|
|
9051
|
+
const { openSession: openSession2 } = await Promise.resolve().then(() => (init_session2(), session_exports2));
|
|
7343
9052
|
return openSession2(this.slug, {
|
|
7344
9053
|
task,
|
|
7345
9054
|
versionId: this.version.versionId,
|
|
@@ -9764,7 +11473,7 @@ var gateway = {
|
|
|
9764
11473
|
init_users();
|
|
9765
11474
|
init_scores();
|
|
9766
11475
|
init_worlds();
|
|
9767
|
-
|
|
11476
|
+
init_session2();
|
|
9768
11477
|
|
|
9769
11478
|
// src/files/index.ts
|
|
9770
11479
|
var files_exports = {};
|
|
@@ -9791,7 +11500,7 @@ __export(files_exports, {
|
|
|
9791
11500
|
uploadFile: () => uploadFile
|
|
9792
11501
|
});
|
|
9793
11502
|
init_worlds();
|
|
9794
|
-
import { createHash as
|
|
11503
|
+
import { createHash as createHash10 } from "crypto";
|
|
9795
11504
|
import * as fs13 from "fs";
|
|
9796
11505
|
import * as path12 from "path";
|
|
9797
11506
|
import { Readable, Transform } from "stream";
|
|
@@ -9856,7 +11565,7 @@ async function confirmUpload(options = {}, fileId, ok = true) {
|
|
|
9856
11565
|
return apiRequest(options, "POST", `${BASE}/confirm`, { fileId, ok });
|
|
9857
11566
|
}
|
|
9858
11567
|
async function sha256Base64(localPath) {
|
|
9859
|
-
const hash =
|
|
11568
|
+
const hash = createHash10("sha256");
|
|
9860
11569
|
for await (const chunk of fs13.createReadStream(localPath)) hash.update(chunk);
|
|
9861
11570
|
return hash.digest("base64");
|
|
9862
11571
|
}
|
|
@@ -9941,7 +11650,7 @@ async function uploadBytes(options = {}, bytes, targetPath, upload = {}) {
|
|
|
9941
11650
|
if (!bytes.length) throw new Error("nothing to upload: the content is empty");
|
|
9942
11651
|
const target = drivePath(targetPath);
|
|
9943
11652
|
const contentType = upload.contentType ?? contentTypeFor(target);
|
|
9944
|
-
const sha2562 =
|
|
11653
|
+
const sha2562 = createHash10("sha256").update(bytes).digest("base64");
|
|
9945
11654
|
const granted = await requestUpload(options, { path: target, contentLength: bytes.length, contentType, sha256: sha2562, ...upload.overwrite ? { overwrite: true } : {} });
|
|
9946
11655
|
try {
|
|
9947
11656
|
await putPresigned(granted.uploadUrl, new Uint8Array(bytes), { contentType, contentLength: bytes.length, sha256: sha2562 });
|
|
@@ -10194,10 +11903,10 @@ function swapValue(text2, needle, replacement) {
|
|
|
10194
11903
|
}
|
|
10195
11904
|
|
|
10196
11905
|
// src/hooks/standInDigits.ts
|
|
10197
|
-
import { createHash as
|
|
11906
|
+
import { createHash as createHash11 } from "crypto";
|
|
10198
11907
|
function standInDigits(realDigits, identityName) {
|
|
10199
11908
|
if (!realDigits) return "";
|
|
10200
|
-
const digest =
|
|
11909
|
+
const digest = createHash11("sha256").update(`${identityName}:${realDigits}`).digest("hex");
|
|
10201
11910
|
let digits = "";
|
|
10202
11911
|
for (let i = 0; i < realDigits.length; i++)
|
|
10203
11912
|
digits += String(parseInt(digest[i % digest.length], 16) % 10);
|
|
@@ -10231,7 +11940,7 @@ var DeclaredStandIn = class _DeclaredStandIn {
|
|
|
10231
11940
|
};
|
|
10232
11941
|
|
|
10233
11942
|
// src/hooks/alias.ts
|
|
10234
|
-
import { createHash as
|
|
11943
|
+
import { createHash as createHash12, createHmac, randomBytes as randomBytes2 } from "crypto";
|
|
10235
11944
|
var GIVEN = [
|
|
10236
11945
|
"John",
|
|
10237
11946
|
"Mary",
|
|
@@ -10503,7 +12212,7 @@ function nameParts(name) {
|
|
|
10503
12212
|
function format(template, parts2) {
|
|
10504
12213
|
return template.replace(/\{(\w+)\}/g, (_, key2) => parts2[key2] ?? "").trim();
|
|
10505
12214
|
}
|
|
10506
|
-
var
|
|
12215
|
+
var pair2 = (real, fake, template) => [
|
|
10507
12216
|
format(template, real),
|
|
10508
12217
|
format(template, fake)
|
|
10509
12218
|
];
|
|
@@ -10563,7 +12272,7 @@ function namePairs(real, fake) {
|
|
|
10563
12272
|
const out = [[real, fake]];
|
|
10564
12273
|
if (realParts.given && realParts.surname) {
|
|
10565
12274
|
for (const template of NAME_FORMS) {
|
|
10566
|
-
const p =
|
|
12275
|
+
const p = pair2(realParts, fakeParts, template);
|
|
10567
12276
|
if (p[0].length > 2 && !p[0].includes("{")) out.push(p);
|
|
10568
12277
|
}
|
|
10569
12278
|
}
|
|
@@ -10601,7 +12310,7 @@ function emailPairs(real, fake) {
|
|
|
10601
12310
|
};
|
|
10602
12311
|
const out = [[real, fake]];
|
|
10603
12312
|
for (const template of EMAIL_FORMS) {
|
|
10604
|
-
const p =
|
|
12313
|
+
const p = pair2(realParts, fakeParts, template);
|
|
10605
12314
|
if (p[0].length > 2) out.push(p);
|
|
10606
12315
|
}
|
|
10607
12316
|
return dedupe(out);
|
|
@@ -11052,9 +12761,9 @@ var AliasMap = class _AliasMap {
|
|
|
11052
12761
|
});
|
|
11053
12762
|
if (alias.role === "private") {
|
|
11054
12763
|
for (const slug of this.slugs) {
|
|
11055
|
-
const standIn = "sha256:" +
|
|
12764
|
+
const standIn = "sha256:" + createHash12("sha256").update(`${slug}:${canonical(alias.kind, alias.display)}`, "utf8").digest("hex");
|
|
11056
12765
|
alias.variants.push([
|
|
11057
|
-
"sha256:" +
|
|
12766
|
+
"sha256:" + createHash12("sha256").update(`${slug}:${alias.canonical}`, "utf8").digest("hex"),
|
|
11058
12767
|
standIn
|
|
11059
12768
|
]);
|
|
11060
12769
|
this.aliasDigests.add(standIn.toLowerCase());
|
|
@@ -11869,7 +13578,7 @@ function inputSchema(shorthand, position) {
|
|
|
11869
13578
|
`${position}.input: expected a table of field = "type"`
|
|
11870
13579
|
);
|
|
11871
13580
|
const properties = {};
|
|
11872
|
-
const
|
|
13581
|
+
const required2 = [];
|
|
11873
13582
|
for (const [name, raw] of Object.entries(shorthand)) {
|
|
11874
13583
|
if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(name))
|
|
11875
13584
|
throw new HookConfigError(
|
|
@@ -11903,9 +13612,9 @@ function inputSchema(shorthand, position) {
|
|
|
11903
13612
|
`${position}.input.${name}: expected "type" or a schema table`
|
|
11904
13613
|
);
|
|
11905
13614
|
properties[name] = schema;
|
|
11906
|
-
if (!optional)
|
|
13615
|
+
if (!optional) required2.push(name);
|
|
11907
13616
|
}
|
|
11908
|
-
return { type: "object", properties, required };
|
|
13617
|
+
return { type: "object", properties, required: required2 };
|
|
11909
13618
|
}
|
|
11910
13619
|
function placeholders(value) {
|
|
11911
13620
|
if (typeof value === "string")
|
|
@@ -14729,11 +16438,20 @@ init_identity();
|
|
|
14729
16438
|
var tracing_exports = {};
|
|
14730
16439
|
__export(tracing_exports, {
|
|
14731
16440
|
IdentitySpanProcessor: () => IdentitySpanProcessor,
|
|
16441
|
+
MAX_MEDIA_BYTES: () => MAX_MEDIA_BYTES,
|
|
16442
|
+
MediaReference: () => MediaReference,
|
|
16443
|
+
MediaUploadError: () => MediaUploadError,
|
|
16444
|
+
MediaUploader: () => MediaUploader,
|
|
16445
|
+
SECRET_KEYS: () => SECRET_KEYS,
|
|
14732
16446
|
SESSION_ID_ATTRIBUTE: () => SESSION_ID_ATTRIBUTE,
|
|
16447
|
+
SecretRedactingSpanProcessor: () => SecretRedactingSpanProcessor,
|
|
14733
16448
|
SessionSpanProcessor: () => SessionSpanProcessor,
|
|
16449
|
+
SpanSecrets: () => SpanSecrets,
|
|
14734
16450
|
USER_ID_ATTRIBUTE: () => USER_ID_ATTRIBUTE,
|
|
16451
|
+
WORLD_SESSION_ID_ATTRIBUTE: () => WORLD_SESSION_ID_ATTRIBUTE,
|
|
14735
16452
|
flush: () => flush,
|
|
14736
16453
|
getAmbientSessionId: () => getAmbientSessionId,
|
|
16454
|
+
getCurrentWorldSessionId: () => getCurrentWorldSessionId,
|
|
14737
16455
|
identify: () => identify,
|
|
14738
16456
|
init: () => init2,
|
|
14739
16457
|
initIsolated: () => initIsolated,
|
|
@@ -14746,11 +16464,13 @@ __export(tracing_exports, {
|
|
|
14746
16464
|
resetAmbientUser: () => resetAmbientUser,
|
|
14747
16465
|
resolveUserId: () => resolveUserId,
|
|
14748
16466
|
shutdown: () => shutdown2,
|
|
14749
|
-
withSession: () => withSession
|
|
16467
|
+
withSession: () => withSession,
|
|
16468
|
+
withWorldSession: () => withWorldSession
|
|
14750
16469
|
});
|
|
14751
16470
|
init_init();
|
|
14752
16471
|
init_identity();
|
|
14753
|
-
|
|
16472
|
+
init_session();
|
|
16473
|
+
init_secrets();
|
|
14754
16474
|
|
|
14755
16475
|
// src/tracing/observe.ts
|
|
14756
16476
|
import { trace as trace3, context as context2, SpanStatusCode } from "@opentelemetry/api";
|
|
@@ -15013,6 +16733,9 @@ async function* observeClaude(stream, options) {
|
|
|
15013
16733
|
}
|
|
15014
16734
|
}
|
|
15015
16735
|
|
|
16736
|
+
// src/tracing/index.ts
|
|
16737
|
+
init_media();
|
|
16738
|
+
|
|
15016
16739
|
// src/index.ts
|
|
15017
16740
|
var tracing = {
|
|
15018
16741
|
...tracing_exports,
|
|
@@ -15031,7 +16754,11 @@ var tracing = {
|
|
|
15031
16754
|
}
|
|
15032
16755
|
};
|
|
15033
16756
|
export {
|
|
16757
|
+
ACTION_NAMES,
|
|
15034
16758
|
AGENT_ID_KEY,
|
|
16759
|
+
ActionTracer,
|
|
16760
|
+
AnthropicComputer,
|
|
16761
|
+
AnthropicComputer20251124,
|
|
15035
16762
|
ApiError,
|
|
15036
16763
|
BROWSER_GONE_PATTERNS,
|
|
15037
16764
|
BROWSER_TIERS,
|
|
@@ -15043,12 +16770,14 @@ export {
|
|
|
15043
16770
|
CALL_BODY_LIMIT_LABEL,
|
|
15044
16771
|
COMPUTER_USE_SPECS,
|
|
15045
16772
|
CheckoutProvenance,
|
|
16773
|
+
ComputerAction,
|
|
15046
16774
|
DEFAULT_BRANCH,
|
|
15047
16775
|
DEFAULT_TIMEOUT_SECONDS,
|
|
15048
16776
|
DEFAULT_VIEWPORT,
|
|
15049
16777
|
DRY_RUN_AGENT,
|
|
15050
16778
|
DRY_RUN_KIND,
|
|
15051
16779
|
DetachedPushError,
|
|
16780
|
+
Display,
|
|
15052
16781
|
DriftError,
|
|
15053
16782
|
DryRunOutcome,
|
|
15054
16783
|
ENV_GATEWAY_HOST,
|
|
@@ -15076,9 +16805,16 @@ export {
|
|
|
15076
16805
|
GatewayToolBlockedError,
|
|
15077
16806
|
HostedDryRunClient,
|
|
15078
16807
|
IDLE_WARNING_MINUTES,
|
|
16808
|
+
KEY_NAMES,
|
|
16809
|
+
KeyChord,
|
|
16810
|
+
NOT_EXECUTED,
|
|
15079
16811
|
NO_GRADER_REASON,
|
|
16812
|
+
NativeComputer,
|
|
16813
|
+
OpenAIComputer,
|
|
16814
|
+
OpenAIPreviewComputer,
|
|
15080
16815
|
PLATFORM_TIMEOUT_DEFAULT_MS,
|
|
15081
16816
|
PLATFORM_TIMEOUT_ENV,
|
|
16817
|
+
PendingSafetyChecks,
|
|
15082
16818
|
Persona,
|
|
15083
16819
|
PersonaError,
|
|
15084
16820
|
PersonasClient,
|
|
@@ -15093,7 +16829,9 @@ export {
|
|
|
15093
16829
|
ReplaySuite,
|
|
15094
16830
|
ReplayTask,
|
|
15095
16831
|
SANDBOX_REQUEST_TIMEOUT_MS,
|
|
16832
|
+
SECRET_KEY,
|
|
15096
16833
|
SESSION_STATES,
|
|
16834
|
+
SPAN_PREFIX,
|
|
15097
16835
|
STATUS_WAIT_CAP_SECONDS,
|
|
15098
16836
|
STRIP_PREFIX,
|
|
15099
16837
|
SUCCESS_METRIC_NAME_KEY,
|
|
@@ -15101,12 +16839,14 @@ export {
|
|
|
15101
16839
|
SURFACE_KINDS,
|
|
15102
16840
|
ScoreError,
|
|
15103
16841
|
ScoresClient,
|
|
16842
|
+
Screen,
|
|
15104
16843
|
SecretScrubber,
|
|
15105
16844
|
SessionLoadError,
|
|
15106
16845
|
SessionRecording,
|
|
15107
16846
|
SessionTrace,
|
|
15108
16847
|
StubMissError,
|
|
15109
16848
|
TRANSFORMS,
|
|
16849
|
+
TaskEditClient,
|
|
15110
16850
|
TaskRun,
|
|
15111
16851
|
TaskSessions,
|
|
15112
16852
|
ToolStubRegistry,
|
|
@@ -15120,6 +16860,7 @@ export {
|
|
|
15120
16860
|
WorldBrowser,
|
|
15121
16861
|
WorldCallTooLarge,
|
|
15122
16862
|
WorldEditClient,
|
|
16863
|
+
WorldRequestLog,
|
|
15123
16864
|
WorldSandboxClient,
|
|
15124
16865
|
WorldSession,
|
|
15125
16866
|
WorldSessionCallError,
|
|
@@ -15208,6 +16949,7 @@ export {
|
|
|
15208
16949
|
parseWorldTaskRefs,
|
|
15209
16950
|
personas,
|
|
15210
16951
|
platformTimeoutMs,
|
|
16952
|
+
playwrightKey,
|
|
15211
16953
|
preserveForm,
|
|
15212
16954
|
propose,
|
|
15213
16955
|
pull,
|
|
@@ -15217,6 +16959,7 @@ export {
|
|
|
15217
16959
|
pyText,
|
|
15218
16960
|
queryRows,
|
|
15219
16961
|
queryRowsSearch,
|
|
16962
|
+
readField,
|
|
15220
16963
|
readLocalMeta,
|
|
15221
16964
|
readToolCallRecords,
|
|
15222
16965
|
rebaseConflicts,
|
|
@@ -15251,6 +16994,7 @@ export {
|
|
|
15251
16994
|
storedForms,
|
|
15252
16995
|
success,
|
|
15253
16996
|
suite,
|
|
16997
|
+
surfaceDescriptor,
|
|
15254
16998
|
surfaceKinds,
|
|
15255
16999
|
taskLabel,
|
|
15256
17000
|
toolCallRecordsIn,
|