@withgateway/sdk 0.2.8 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +24 -8
- package/dist/cli.js +2695 -657
- package/dist/cli.js.map +1 -1
- package/dist/cli.mjs +2675 -637
- 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 +1443 -36
- package/dist/files/index.js.map +1 -1
- package/dist/files/index.mjs +1441 -28
- package/dist/files/index.mjs.map +1 -1
- package/dist/{index-Cz8Q6Keo.d.mts → index-D6oi1TWE.d.mts} +93 -34
- package/dist/{index-BO2SNSgy.d.ts → index-DAb-FCMg.d.ts} +93 -34
- package/dist/index.d.mts +4 -3
- package/dist/index.d.ts +4 -3
- package/dist/index.js +1986 -235
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1941 -218
- 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 +1440 -33
- package/dist/traces/index.js.map +1 -1
- package/dist/traces/index.mjs +1438 -25
- package/dist/traces/index.mjs.map +1 -1
- package/dist/tracing/index.d.mts +2 -1
- package/dist/tracing/index.d.ts +2 -1
- package/dist/tracing/index.js +512 -11
- package/dist/tracing/index.js.map +1 -1
- package/dist/tracing/index.mjs +501 -10
- package/dist/tracing/index.mjs.map +1 -1
- package/dist/worlds/index.d.mts +614 -25
- package/dist/worlds/index.d.ts +614 -25
- package/dist/worlds/index.js +1923 -214
- package/dist/worlds/index.js.map +1 -1
- package/dist/worlds/index.mjs +1910 -201
- package/dist/worlds/index.mjs.map +1 -1
- package/package.json +1 -1
- package/runtime/gatewaysdk/environment/_toml.py +3 -10
- package/runtime/gatewaysdk/environment/schema/api.py +38 -56
- package/runtime/gatewaysdk/environment/schema/grading.py +1 -5
- package/runtime/gatewaysdk/environment/schema/host.py +53 -90
- package/runtime/gatewaysdk/environment/schema/local.py +15 -7
- package/runtime/gatewaysdk/environment/schema/runtime.py +9 -9
- package/runtime/gatewaysdk/environment/schema/skills/benchmarks-getting-started/SKILL.md +3 -3
- package/runtime/gatewaysdk/environment/schema/skills/connector-schema-authoring/SKILL.md +1 -1
- package/runtime/gatewaysdk/environment/schema/skills/worlds-getting-started/SKILL.md +18 -18
- package/runtime/gatewaysdk/environment/schema/skills/worlds-getting-started/references/cli-mcp-map.md +4 -2
- package/runtime/gatewaysdk/environment/schema/skills/worlds-getting-started/references/gotchas.md +5 -1
- package/runtime/gatewaysdk/environment/schema/skills/worlds-getting-started/references/new-world-sandbox.md +5 -3
- package/runtime/gatewaysdk/environment/schema/store.py +15 -6
- package/runtime/gatewaysdk/environment/schema/tasks.py +25 -1
- package/skills/benchmarks-getting-started/SKILL.md +3 -3
- package/skills/connector-schema-authoring/SKILL.md +1 -1
- package/skills/connector-schema-authoring/world-schema.md +1 -1
- package/skills/worlds-getting-started/SKILL.md +18 -18
- package/skills/worlds-getting-started/references/cli-mcp-map.md +4 -2
- package/skills/worlds-getting-started/references/gotchas.md +5 -1
- package/skills/worlds-getting-started/references/new-world-sandbox.md +5 -3
package/dist/index.mjs
CHANGED
|
@@ -450,6 +450,115 @@ var init_scores = __esm({
|
|
|
450
450
|
}
|
|
451
451
|
});
|
|
452
452
|
|
|
453
|
+
// src/worlds/transport.ts
|
|
454
|
+
function platformTimeoutMs(env = process.env) {
|
|
455
|
+
const raw = env[PLATFORM_TIMEOUT_ENV];
|
|
456
|
+
if (raw === void 0 || raw === "") return PLATFORM_TIMEOUT_DEFAULT_MS;
|
|
457
|
+
const value = Number(raw);
|
|
458
|
+
if (Number.isInteger(value) && value > 0) return value;
|
|
459
|
+
throw new Error(`${PLATFORM_TIMEOUT_ENV} must be a positive whole number of milliseconds, not \`${raw}\`.`);
|
|
460
|
+
}
|
|
461
|
+
var PLATFORM_TIMEOUT_ENV, PLATFORM_TIMEOUT_DEFAULT_MS, CHECK_HOST, RETRY, CAUSES, UNKNOWN_CAUSE, TransportCause, UnreachableError, PlatformTransport;
|
|
462
|
+
var init_transport = __esm({
|
|
463
|
+
"src/worlds/transport.ts"() {
|
|
464
|
+
"use strict";
|
|
465
|
+
PLATFORM_TIMEOUT_ENV = "GATEWAY_TIMEOUT_MS";
|
|
466
|
+
PLATFORM_TIMEOUT_DEFAULT_MS = 12e4;
|
|
467
|
+
CHECK_HOST = "Check GATEWAY_HOST (or --host) points at a running platform, then retry.";
|
|
468
|
+
RETRY = "Retry; if it repeats, check the network between here and the platform.";
|
|
469
|
+
CAUSES = {
|
|
470
|
+
ECONNREFUSED: { reason: "connection refused", next: CHECK_HOST },
|
|
471
|
+
ENOTFOUND: { reason: "DNS lookup failed", next: CHECK_HOST },
|
|
472
|
+
EAI_AGAIN: { reason: "DNS lookup failed", next: CHECK_HOST },
|
|
473
|
+
ETIMEDOUT: { reason: "connect timed out", next: CHECK_HOST },
|
|
474
|
+
UND_ERR_CONNECT_TIMEOUT: { reason: "connect timed out", next: CHECK_HOST },
|
|
475
|
+
EHOSTUNREACH: { reason: "host unreachable", next: CHECK_HOST },
|
|
476
|
+
ENETUNREACH: { reason: "network unreachable", next: RETRY },
|
|
477
|
+
ECONNRESET: { reason: "connection dropped", next: RETRY },
|
|
478
|
+
UND_ERR_SOCKET: { reason: "connection dropped", next: RETRY },
|
|
479
|
+
EPIPE: { reason: "connection dropped", next: RETRY }
|
|
480
|
+
};
|
|
481
|
+
UNKNOWN_CAUSE = { reason: "network error", next: CHECK_HOST };
|
|
482
|
+
TransportCause = class _TransportCause {
|
|
483
|
+
constructor(reason, detail, next) {
|
|
484
|
+
this.reason = reason;
|
|
485
|
+
this.detail = detail;
|
|
486
|
+
this.next = next;
|
|
487
|
+
}
|
|
488
|
+
reason;
|
|
489
|
+
detail;
|
|
490
|
+
next;
|
|
491
|
+
static timeout(timeoutMs) {
|
|
492
|
+
return new _TransportCause(
|
|
493
|
+
`timed out after ${timeoutMs / 1e3}s`,
|
|
494
|
+
null,
|
|
495
|
+
`Retry; if the platform is slow, raise ${PLATFORM_TIMEOUT_ENV} (milliseconds per request).`
|
|
496
|
+
);
|
|
497
|
+
}
|
|
498
|
+
static of(error) {
|
|
499
|
+
const cause = error instanceof Error && error.cause instanceof Error ? error.cause : void 0;
|
|
500
|
+
const code = cause && "code" in cause && typeof cause.code === "string" ? cause.code : null;
|
|
501
|
+
const message = cause?.message ?? (error instanceof Error ? error.message : String(error));
|
|
502
|
+
const known = code && CAUSES[code] || UNKNOWN_CAUSE;
|
|
503
|
+
return new _TransportCause(known.reason, code ? `${code}: ${message}` : message, known.next);
|
|
504
|
+
}
|
|
505
|
+
describe() {
|
|
506
|
+
return this.detail === null ? this.reason : `${this.reason} (${this.detail})`;
|
|
507
|
+
}
|
|
508
|
+
};
|
|
509
|
+
UnreachableError = class extends Error {
|
|
510
|
+
constructor(host, method, route, failure) {
|
|
511
|
+
super(`${method} ${route}: no answer from ${host}: ${failure.describe()}. ${failure.next}`);
|
|
512
|
+
this.host = host;
|
|
513
|
+
this.method = method;
|
|
514
|
+
this.route = route;
|
|
515
|
+
this.failure = failure;
|
|
516
|
+
this.name = "UnreachableError";
|
|
517
|
+
}
|
|
518
|
+
host;
|
|
519
|
+
method;
|
|
520
|
+
route;
|
|
521
|
+
failure;
|
|
522
|
+
};
|
|
523
|
+
PlatformTransport = class {
|
|
524
|
+
constructor(endpoint, timeoutMs = platformTimeoutMs()) {
|
|
525
|
+
this.endpoint = endpoint;
|
|
526
|
+
this.timeoutMs = timeoutMs;
|
|
527
|
+
}
|
|
528
|
+
endpoint;
|
|
529
|
+
timeoutMs;
|
|
530
|
+
/** A request that legitimately takes longer (a sandbox exec, a world create) waits its own budget; every other one waits the default. */
|
|
531
|
+
budget(ownMs) {
|
|
532
|
+
return Math.max(ownMs ?? 0, this.timeoutMs);
|
|
533
|
+
}
|
|
534
|
+
async send(method, route, body, opts = {}) {
|
|
535
|
+
const timeoutMs = this.budget(opts.timeoutMs);
|
|
536
|
+
const payload = body === void 0 ? {} : { body: JSON.stringify(body) };
|
|
537
|
+
const controller = new AbortController();
|
|
538
|
+
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
539
|
+
try {
|
|
540
|
+
const res = await fetch(`${this.endpoint.host}${route}`, {
|
|
541
|
+
method,
|
|
542
|
+
headers: {
|
|
543
|
+
"content-type": "application/json",
|
|
544
|
+
accept: "application/json",
|
|
545
|
+
authorization: "Basic " + Buffer.from(`${this.endpoint.publicKey}:${this.endpoint.secretKey}`).toString("base64")
|
|
546
|
+
},
|
|
547
|
+
...payload,
|
|
548
|
+
signal: controller.signal
|
|
549
|
+
});
|
|
550
|
+
return { status: res.status, ok: res.ok, text: await res.text() };
|
|
551
|
+
} catch (error) {
|
|
552
|
+
const cause = controller.signal.aborted ? TransportCause.timeout(timeoutMs) : TransportCause.of(error);
|
|
553
|
+
throw new UnreachableError(this.endpoint.host, method, route, cause);
|
|
554
|
+
} finally {
|
|
555
|
+
clearTimeout(timer);
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
};
|
|
559
|
+
}
|
|
560
|
+
});
|
|
561
|
+
|
|
453
562
|
// src/worlds/browserReconnect.ts
|
|
454
563
|
async function closeConnection(c) {
|
|
455
564
|
await c.context.close();
|
|
@@ -633,7 +742,7 @@ function withoutUiToken(url) {
|
|
|
633
742
|
const [beforeHash, hash] = splitHash(url);
|
|
634
743
|
const q = beforeHash.indexOf("?");
|
|
635
744
|
if (q < 0) return url;
|
|
636
|
-
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);
|
|
637
746
|
return beforeHash.slice(0, q) + (kept.length ? `?${kept.join("&")}` : "") + hash;
|
|
638
747
|
}
|
|
639
748
|
function splitHash(url) {
|
|
@@ -768,7 +877,7 @@ var SURFACE_KINDS, BROWSER_TIERS, DEFAULT_VIEWPORT, SETTLE_TIMEOUT_MS, SETTLE_QU
|
|
|
768
877
|
var init_browser = __esm({
|
|
769
878
|
"src/worlds/browser.ts"() {
|
|
770
879
|
"use strict";
|
|
771
|
-
|
|
880
|
+
init_session2();
|
|
772
881
|
init_browserReconnect();
|
|
773
882
|
SURFACE_KINDS = ["tools", "api", "ui", "browser"];
|
|
774
883
|
BROWSER_TIERS = ["standard", "premium"];
|
|
@@ -914,6 +1023,10 @@ var init_browser = __esm({
|
|
|
914
1023
|
get agentId() {
|
|
915
1024
|
return this.recorder?.agentId ?? null;
|
|
916
1025
|
}
|
|
1026
|
+
/** `text` with this session's credentials (UI token, browser address) removed. */
|
|
1027
|
+
scrub(text2) {
|
|
1028
|
+
return this.scrubber.scrub(text2);
|
|
1029
|
+
}
|
|
917
1030
|
watchNetwork(page) {
|
|
918
1031
|
page.on("request", () => {
|
|
919
1032
|
this.inflight += 1;
|
|
@@ -1195,8 +1308,1271 @@ var init_browser = __esm({
|
|
|
1195
1308
|
signature: "browser_back()",
|
|
1196
1309
|
doc: "Go back one page in history."
|
|
1197
1310
|
}
|
|
1198
|
-
];
|
|
1199
|
-
str = (v, fallback) => typeof v === "string" && v.length > 0 ? v : fallback;
|
|
1311
|
+
];
|
|
1312
|
+
str = (v, fallback) => typeof v === "string" && v.length > 0 ? v : fallback;
|
|
1313
|
+
}
|
|
1314
|
+
});
|
|
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();
|
|
1200
2576
|
}
|
|
1201
2577
|
});
|
|
1202
2578
|
|
|
@@ -1253,6 +2629,75 @@ var init_sessionContract = __esm({
|
|
|
1253
2629
|
}
|
|
1254
2630
|
});
|
|
1255
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
|
+
|
|
1256
2701
|
// src/worlds/taskRef.ts
|
|
1257
2702
|
var isTaskIdRef, isTaskSpec, taskLabel, assertTaskRef;
|
|
1258
2703
|
var init_taskRef = __esm({
|
|
@@ -1277,8 +2722,8 @@ var init_taskRef = __esm({
|
|
|
1277
2722
|
});
|
|
1278
2723
|
|
|
1279
2724
|
// src/worlds/session.ts
|
|
1280
|
-
var
|
|
1281
|
-
__export(
|
|
2725
|
+
var session_exports2 = {};
|
|
2726
|
+
__export(session_exports2, {
|
|
1282
2727
|
WorldSession: () => WorldSession,
|
|
1283
2728
|
WorldSessionCallError: () => WorldSessionCallError,
|
|
1284
2729
|
WorldSessionTimeout: () => WorldSessionTimeout,
|
|
@@ -1332,7 +2777,7 @@ function schemaFromSignature(spec) {
|
|
|
1332
2777
|
};
|
|
1333
2778
|
const inside = /\(([\s\S]*)\)\s*$/.exec(spec.signature.trim())?.[1] ?? "";
|
|
1334
2779
|
const properties = {};
|
|
1335
|
-
const
|
|
2780
|
+
const required2 = [];
|
|
1336
2781
|
const params = [];
|
|
1337
2782
|
let depth = 0;
|
|
1338
2783
|
let current = "";
|
|
@@ -1353,7 +2798,7 @@ function schemaFromSignature(spec) {
|
|
|
1353
2798
|
if (!name) continue;
|
|
1354
2799
|
if (eq === -1) {
|
|
1355
2800
|
properties[name] = { type: "string" };
|
|
1356
|
-
|
|
2801
|
+
required2.push(name);
|
|
1357
2802
|
continue;
|
|
1358
2803
|
}
|
|
1359
2804
|
const value = param.slice(eq + 1).trim();
|
|
@@ -1367,7 +2812,7 @@ function schemaFromSignature(spec) {
|
|
|
1367
2812
|
function: {
|
|
1368
2813
|
name: modelToolName(spec.name),
|
|
1369
2814
|
description: spec.doc ?? spec.name,
|
|
1370
|
-
parameters: { type: "object", properties, required }
|
|
2815
|
+
parameters: { type: "object", properties, required: required2 }
|
|
1371
2816
|
}
|
|
1372
2817
|
};
|
|
1373
2818
|
}
|
|
@@ -1436,13 +2881,16 @@ async function runSessions(opts) {
|
|
|
1436
2881
|
task = taskLabel(taskRef, session.taskInfo);
|
|
1437
2882
|
await session.ready();
|
|
1438
2883
|
const toolkit = await session.toolkit();
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
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
|
+
);
|
|
1446
2894
|
const graded = await session.grade();
|
|
1447
2895
|
const result = {
|
|
1448
2896
|
task,
|
|
@@ -1480,12 +2928,14 @@ async function runSessions(opts) {
|
|
|
1480
2928
|
};
|
|
1481
2929
|
}
|
|
1482
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;
|
|
1483
|
-
var
|
|
2931
|
+
var init_session2 = __esm({
|
|
1484
2932
|
"src/worlds/session.ts"() {
|
|
1485
2933
|
"use strict";
|
|
1486
2934
|
init_worlds();
|
|
1487
2935
|
init_browser();
|
|
2936
|
+
init_nativeComputer();
|
|
1488
2937
|
init_sessionContract();
|
|
2938
|
+
init_session();
|
|
1489
2939
|
init_taskRef();
|
|
1490
2940
|
init_taskRef();
|
|
1491
2941
|
READY_TIMEOUT_MS = 10 * 6e4;
|
|
@@ -1639,6 +3089,12 @@ var init_session = __esm({
|
|
|
1639
3089
|
computerUseTools(browser) {
|
|
1640
3090
|
return computerUseToolkit(browser);
|
|
1641
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
|
+
}
|
|
1642
3098
|
/** The session's latest platform state (one request, no waiting). */
|
|
1643
3099
|
async status() {
|
|
1644
3100
|
const fresh = await apiRequest(
|
|
@@ -1873,6 +3329,21 @@ var init_session = __esm({
|
|
|
1873
3329
|
{ keepWarm: opts.keepWarm ?? false }
|
|
1874
3330
|
);
|
|
1875
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
|
+
}
|
|
1876
3347
|
};
|
|
1877
3348
|
OPEN_SESSION_OPTION_KEYS = /* @__PURE__ */ new Set([
|
|
1878
3349
|
"task",
|
|
@@ -2022,7 +3493,11 @@ function fromResponse(answer, options) {
|
|
|
2022
3493
|
const worlds = {};
|
|
2023
3494
|
for (const [alias, state2] of Object.entries(answer.sessions)) {
|
|
2024
3495
|
sessions2[alias] = new WorldSession(state2.sessionId, state2, options);
|
|
2025
|
-
worlds[alias] = {
|
|
3496
|
+
worlds[alias] = {
|
|
3497
|
+
slug: state2.slug,
|
|
3498
|
+
ref: state2.ref,
|
|
3499
|
+
private: state2.private ?? null
|
|
3500
|
+
};
|
|
2026
3501
|
}
|
|
2027
3502
|
return new TaskSessions(
|
|
2028
3503
|
answer.taskId,
|
|
@@ -2096,6 +3571,7 @@ async function attachTask(taskId, options = {}) {
|
|
|
2096
3571
|
{
|
|
2097
3572
|
slug: row.slug ?? "",
|
|
2098
3573
|
ref: null,
|
|
3574
|
+
private: null,
|
|
2099
3575
|
versionId: row.versionId,
|
|
2100
3576
|
sessionId: row.sessionId,
|
|
2101
3577
|
ready: row.ready,
|
|
@@ -2125,7 +3601,7 @@ async function attachManifest(manifest, options = {}) {
|
|
|
2125
3601
|
Object.fromEntries(
|
|
2126
3602
|
Object.entries(manifest.sessions).map(([alias, entry]) => [
|
|
2127
3603
|
alias,
|
|
2128
|
-
{ slug: entry.slug, ref: entry.ref }
|
|
3604
|
+
{ slug: entry.slug, ref: entry.ref, private: entry.private ?? null }
|
|
2129
3605
|
])
|
|
2130
3606
|
)
|
|
2131
3607
|
);
|
|
@@ -2139,12 +3615,13 @@ var init_taskSessions = __esm({
|
|
|
2139
3615
|
"use strict";
|
|
2140
3616
|
init_worlds();
|
|
2141
3617
|
init_browser();
|
|
2142
|
-
|
|
3618
|
+
init_session2();
|
|
2143
3619
|
TASK_SESSIONS = "/api/public/world-task-sessions";
|
|
2144
3620
|
VERIFIER_REWARD_PREFIX = "x.";
|
|
2145
3621
|
manifestSession = (s, state2, world) => ({
|
|
2146
3622
|
slug: world.slug,
|
|
2147
3623
|
ref: world.ref,
|
|
3624
|
+
private: world.private,
|
|
2148
3625
|
versionId: state2.versionId,
|
|
2149
3626
|
sessionId: state2.sessionId,
|
|
2150
3627
|
ready: state2.ready,
|
|
@@ -2179,10 +3656,10 @@ var init_taskSessions = __esm({
|
|
|
2179
3656
|
sessions;
|
|
2180
3657
|
worlds;
|
|
2181
3658
|
hash;
|
|
2182
|
-
/** This alias's
|
|
2183
|
-
*
|
|
3659
|
+
/** This alias's world as recorded at open/attach — what a `TaskRun`
|
|
3660
|
+
* filing needs to name, without exposing the whole map. */
|
|
2184
3661
|
worldRef(alias) {
|
|
2185
|
-
return this.worlds[alias] ?? { slug: "", ref: null };
|
|
3662
|
+
return this.worlds[alias] ?? { slug: "", ref: null, private: null };
|
|
2186
3663
|
}
|
|
2187
3664
|
/** The aliases, in the spec's order. */
|
|
2188
3665
|
get aliases() {
|
|
@@ -2340,7 +3817,7 @@ var init_evals = __esm({
|
|
|
2340
3817
|
});
|
|
2341
3818
|
|
|
2342
3819
|
// src/tracing/identity.ts
|
|
2343
|
-
import { AsyncLocalStorage as
|
|
3820
|
+
import { AsyncLocalStorage as AsyncLocalStorage3 } from "async_hooks";
|
|
2344
3821
|
import { isSpanContextValid as isSpanContextValid2, trace as trace2 } from "@opentelemetry/api";
|
|
2345
3822
|
function resolveUserId() {
|
|
2346
3823
|
const contextual = currentUserStorage.getStore();
|
|
@@ -2393,7 +3870,7 @@ var init_identity = __esm({
|
|
|
2393
3870
|
"use strict";
|
|
2394
3871
|
init_users();
|
|
2395
3872
|
USER_ID_ATTRIBUTE = "gateway.user.id";
|
|
2396
|
-
currentUserStorage = new
|
|
3873
|
+
currentUserStorage = new AsyncLocalStorage3();
|
|
2397
3874
|
IdentitySpanProcessor = class {
|
|
2398
3875
|
onStart(span, _parentContext) {
|
|
2399
3876
|
const userId = resolveUserId();
|
|
@@ -2411,43 +3888,224 @@ var init_identity = __esm({
|
|
|
2411
3888
|
}
|
|
2412
3889
|
});
|
|
2413
3890
|
|
|
2414
|
-
// src/tracing/
|
|
2415
|
-
|
|
2416
|
-
|
|
2417
|
-
|
|
2418
|
-
|
|
2419
|
-
|
|
2420
|
-
|
|
2421
|
-
}
|
|
2422
|
-
|
|
2423
|
-
|
|
2424
|
-
return currentSessionStorage.getStore();
|
|
3891
|
+
// src/tracing/secrets.ts
|
|
3892
|
+
function jsonOrUndefined(text2) {
|
|
3893
|
+
let parsed;
|
|
3894
|
+
try {
|
|
3895
|
+
parsed = JSON.parse(text2);
|
|
3896
|
+
} catch {
|
|
3897
|
+
return void 0;
|
|
3898
|
+
}
|
|
3899
|
+
if (typeof parsed === "string") return parsed;
|
|
3900
|
+
return parsed !== null && typeof parsed === "object" ? parsed : void 0;
|
|
2425
3901
|
}
|
|
2426
|
-
function
|
|
2427
|
-
return
|
|
2428
|
-
|
|
2429
|
-
|
|
2430
|
-
|
|
3902
|
+
function encodings(value) {
|
|
3903
|
+
return [value, percentEncoded(value), JSON.stringify(value).slice(1, -1)];
|
|
3904
|
+
}
|
|
3905
|
+
function percentEncoded(value) {
|
|
3906
|
+
try {
|
|
3907
|
+
return encodeURIComponent(value);
|
|
3908
|
+
} catch {
|
|
3909
|
+
return value;
|
|
3910
|
+
}
|
|
3911
|
+
}
|
|
3912
|
+
function union(sets) {
|
|
3913
|
+
return new Set(sets.flatMap((set) => [...set]));
|
|
3914
|
+
}
|
|
3915
|
+
function leaves(value) {
|
|
3916
|
+
if (typeof value === "string") {
|
|
3917
|
+
return [...value].length >= MIN_SECRET_LENGTH ? /* @__PURE__ */ new Set([value]) : /* @__PURE__ */ new Set();
|
|
3918
|
+
}
|
|
3919
|
+
if (Array.isArray(value)) return union(value.map(leaves));
|
|
3920
|
+
if (value === null || typeof value !== "object") return /* @__PURE__ */ new Set();
|
|
3921
|
+
return union(Object.values(value).map(leaves));
|
|
3922
|
+
}
|
|
3923
|
+
function sameAttributes(before, after) {
|
|
3924
|
+
const keys = Object.keys(before);
|
|
3925
|
+
if (keys.length !== Object.keys(after).length) return false;
|
|
3926
|
+
return keys.every(
|
|
3927
|
+
(key2) => before[key2] === after[key2] || sameArray(before[key2], after[key2])
|
|
3928
|
+
);
|
|
3929
|
+
}
|
|
3930
|
+
function sameArray(before, after) {
|
|
3931
|
+
if (!Array.isArray(before) || !Array.isArray(after)) return false;
|
|
3932
|
+
return before.length === after.length && before.every((item, i) => item === after[i]);
|
|
3933
|
+
}
|
|
3934
|
+
function scrubbedRead(reads, property) {
|
|
3935
|
+
return typeof property === "string" && property in reads ? reads[property] : void 0;
|
|
3936
|
+
}
|
|
3937
|
+
function viewOf(span, reads) {
|
|
3938
|
+
const view = new Proxy(span, {
|
|
3939
|
+
get(target, property) {
|
|
3940
|
+
const read = scrubbedRead(reads, property);
|
|
3941
|
+
if (read) return read();
|
|
3942
|
+
const value = Reflect.get(target, property, target);
|
|
3943
|
+
if (typeof value !== "function") return value;
|
|
3944
|
+
return (...args) => {
|
|
3945
|
+
const result = value.apply(target, args);
|
|
3946
|
+
return result === target ? view : result;
|
|
3947
|
+
};
|
|
3948
|
+
},
|
|
3949
|
+
getOwnPropertyDescriptor(target, property) {
|
|
3950
|
+
const descriptor = Reflect.getOwnPropertyDescriptor(target, property);
|
|
3951
|
+
const read = scrubbedRead(reads, property);
|
|
3952
|
+
if (!read || !descriptor || !("value" in descriptor)) return descriptor;
|
|
3953
|
+
return { ...descriptor, value: read() };
|
|
3954
|
+
}
|
|
2431
3955
|
});
|
|
3956
|
+
return view;
|
|
2432
3957
|
}
|
|
2433
|
-
var
|
|
2434
|
-
var
|
|
2435
|
-
"src/tracing/
|
|
3958
|
+
var SECRET_KEYS, REDACTED2, MIN_SECRET_LENGTH, SpanSecrets, SPAN_SECRETS, SecretRedactingSpanProcessor;
|
|
3959
|
+
var init_secrets = __esm({
|
|
3960
|
+
"src/tracing/secrets.ts"() {
|
|
2436
3961
|
"use strict";
|
|
2437
|
-
|
|
2438
|
-
|
|
2439
|
-
|
|
2440
|
-
|
|
2441
|
-
|
|
2442
|
-
|
|
2443
|
-
|
|
3962
|
+
SECRET_KEYS = /* @__PURE__ */ new Set([
|
|
3963
|
+
"authorization_token",
|
|
3964
|
+
"authorizationToken"
|
|
3965
|
+
]);
|
|
3966
|
+
REDACTED2 = "[redacted: holds a credential]";
|
|
3967
|
+
MIN_SECRET_LENGTH = 8;
|
|
3968
|
+
SpanSecrets = class {
|
|
3969
|
+
constructor(keys = SECRET_KEYS) {
|
|
3970
|
+
this.keys = keys;
|
|
3971
|
+
}
|
|
3972
|
+
keys;
|
|
3973
|
+
isSecret(key2) {
|
|
3974
|
+
return this.keys.has(key2);
|
|
3975
|
+
}
|
|
3976
|
+
drops(attribute) {
|
|
3977
|
+
return this.mentions(attribute);
|
|
3978
|
+
}
|
|
3979
|
+
strip(value) {
|
|
3980
|
+
if (typeof value === "string") return this.stripNested(value);
|
|
3981
|
+
if (Array.isArray(value)) return value.map((item) => this.strip(item));
|
|
3982
|
+
if (value === null || typeof value !== "object") return value;
|
|
3983
|
+
return Object.fromEntries(
|
|
3984
|
+
Object.entries(value).filter(([key2]) => !this.isSecret(key2)).map(([key2, item]) => [key2, this.strip(item)])
|
|
3985
|
+
);
|
|
3986
|
+
}
|
|
3987
|
+
scrubAttribute(value) {
|
|
3988
|
+
try {
|
|
3989
|
+
return this.scrubbedValue(value);
|
|
3990
|
+
} catch {
|
|
3991
|
+
return Array.isArray(value) ? [REDACTED2] : REDACTED2;
|
|
2444
3992
|
}
|
|
2445
3993
|
}
|
|
2446
|
-
|
|
3994
|
+
scrubbedValue(value) {
|
|
3995
|
+
if (typeof value === "string") return this.scrubbedText(value);
|
|
3996
|
+
if (!Array.isArray(value)) return value;
|
|
3997
|
+
const results = value.map(
|
|
3998
|
+
(item) => typeof item === "string" ? this.cleaned(item) : { text: item, removed: /* @__PURE__ */ new Set() }
|
|
3999
|
+
);
|
|
4000
|
+
const removed = new Set(results.flatMap((r) => [...r.removed]));
|
|
4001
|
+
const scrubbed = results.map((r) => r.text);
|
|
4002
|
+
const withheld = scrubbed.some(
|
|
4003
|
+
(item) => typeof item === "string" && this.carries(item, removed)
|
|
4004
|
+
);
|
|
4005
|
+
return withheld ? [REDACTED2] : scrubbed;
|
|
2447
4006
|
}
|
|
2448
|
-
|
|
4007
|
+
scrubAttributes(attributes) {
|
|
4008
|
+
return Object.fromEntries(
|
|
4009
|
+
Object.entries(attributes).filter(([key2]) => !this.drops(key2)).map(([key2, value]) => [key2, this.scrubAttribute(value)])
|
|
4010
|
+
);
|
|
2449
4011
|
}
|
|
2450
|
-
|
|
4012
|
+
mentions(text2) {
|
|
4013
|
+
return [...this.keys].some((key2) => text2.includes(key2));
|
|
4014
|
+
}
|
|
4015
|
+
scrubbedText(text2) {
|
|
4016
|
+
const { text: cleaned, removed } = this.cleaned(text2);
|
|
4017
|
+
return this.carries(cleaned, removed) ? REDACTED2 : cleaned;
|
|
4018
|
+
}
|
|
4019
|
+
cleaned(text2) {
|
|
4020
|
+
if (!this.mentions(text2)) return { text: text2, removed: /* @__PURE__ */ new Set() };
|
|
4021
|
+
const parsed = jsonOrUndefined(text2);
|
|
4022
|
+
if (parsed === void 0) return { text: REDACTED2, removed: /* @__PURE__ */ new Set() };
|
|
4023
|
+
return {
|
|
4024
|
+
text: JSON.stringify(this.strip(parsed)),
|
|
4025
|
+
removed: this.removed(parsed)
|
|
4026
|
+
};
|
|
4027
|
+
}
|
|
4028
|
+
carries(text2, removed) {
|
|
4029
|
+
if (text2 === REDACTED2 || this.mentions(text2)) return true;
|
|
4030
|
+
return [...removed].some(
|
|
4031
|
+
(value) => encodings(value).some((form) => text2.includes(form))
|
|
4032
|
+
);
|
|
4033
|
+
}
|
|
4034
|
+
removed(value) {
|
|
4035
|
+
if (typeof value === "string") {
|
|
4036
|
+
const nested = this.mentions(value) ? jsonOrUndefined(value) : void 0;
|
|
4037
|
+
return nested === void 0 ? /* @__PURE__ */ new Set() : this.removed(nested);
|
|
4038
|
+
}
|
|
4039
|
+
if (Array.isArray(value)) return union(value.map((v) => this.removed(v)));
|
|
4040
|
+
if (value === null || typeof value !== "object") return /* @__PURE__ */ new Set();
|
|
4041
|
+
return union(
|
|
4042
|
+
Object.entries(value).map(
|
|
4043
|
+
([key2, item]) => this.isSecret(key2) ? leaves(item) : this.removed(item)
|
|
4044
|
+
)
|
|
4045
|
+
);
|
|
4046
|
+
}
|
|
4047
|
+
stripNested(text2) {
|
|
4048
|
+
if (!this.mentions(text2)) return text2;
|
|
4049
|
+
const parsed = jsonOrUndefined(text2);
|
|
4050
|
+
if (parsed === void 0) return text2;
|
|
4051
|
+
return JSON.stringify(this.strip(parsed));
|
|
4052
|
+
}
|
|
4053
|
+
};
|
|
4054
|
+
SPAN_SECRETS = new SpanSecrets();
|
|
4055
|
+
SecretRedactingSpanProcessor = class {
|
|
4056
|
+
constructor(inner, secrets = SPAN_SECRETS) {
|
|
4057
|
+
this.inner = inner;
|
|
4058
|
+
this.secrets = secrets;
|
|
4059
|
+
}
|
|
4060
|
+
inner;
|
|
4061
|
+
secrets;
|
|
4062
|
+
views = /* @__PURE__ */ new WeakMap();
|
|
4063
|
+
onStart(span, parentContext) {
|
|
4064
|
+
this.inner.onStart(this.viewFor(span), parentContext);
|
|
4065
|
+
}
|
|
4066
|
+
onEnd(span) {
|
|
4067
|
+
const view = this.viewFor(span);
|
|
4068
|
+
try {
|
|
4069
|
+
void [view.attributes, view.events, view.status];
|
|
4070
|
+
} catch (error) {
|
|
4071
|
+
console.warn(
|
|
4072
|
+
`[gatewaysdk.tracing] Dropped span "${span.name}": could not redact it: ${error?.name}`
|
|
4073
|
+
);
|
|
4074
|
+
return;
|
|
4075
|
+
}
|
|
4076
|
+
this.inner.onEnd(view);
|
|
4077
|
+
}
|
|
4078
|
+
viewFor(span) {
|
|
4079
|
+
const known = this.views.get(span);
|
|
4080
|
+
if (known) return known;
|
|
4081
|
+
const view = viewOf(span, {
|
|
4082
|
+
attributes: () => this.scrubbedAttributes(span.attributes),
|
|
4083
|
+
events: () => span.events.map((event) => this.scrubbedEvent(event)),
|
|
4084
|
+
status: () => this.scrubbedStatus(span.status)
|
|
4085
|
+
});
|
|
4086
|
+
this.views.set(span, view);
|
|
4087
|
+
return view;
|
|
4088
|
+
}
|
|
4089
|
+
forceFlush() {
|
|
4090
|
+
return this.inner.forceFlush();
|
|
4091
|
+
}
|
|
4092
|
+
shutdown() {
|
|
4093
|
+
return this.inner.shutdown();
|
|
4094
|
+
}
|
|
4095
|
+
scrubbedAttributes(attributes) {
|
|
4096
|
+
const clean = this.secrets.scrubAttributes(attributes);
|
|
4097
|
+
return sameAttributes(attributes, clean) ? attributes : clean;
|
|
4098
|
+
}
|
|
4099
|
+
scrubbedStatus(status) {
|
|
4100
|
+
if (!status.message) return status;
|
|
4101
|
+
const message = this.secrets.scrubAttribute(status.message);
|
|
4102
|
+
return message === status.message ? status : { ...status, message };
|
|
4103
|
+
}
|
|
4104
|
+
scrubbedEvent(event) {
|
|
4105
|
+
if (!event.attributes) return event;
|
|
4106
|
+
const attributes = this.scrubbedAttributes(event.attributes);
|
|
4107
|
+
if (attributes === event.attributes) return event;
|
|
4108
|
+
return { ...event, attributes };
|
|
2451
4109
|
}
|
|
2452
4110
|
};
|
|
2453
4111
|
}
|
|
@@ -2458,7 +4116,7 @@ var require_package = __commonJS({
|
|
|
2458
4116
|
"package.json"(exports, module) {
|
|
2459
4117
|
module.exports = {
|
|
2460
4118
|
name: "@withgateway/sdk",
|
|
2461
|
-
version: "0.
|
|
4119
|
+
version: "0.3.0",
|
|
2462
4120
|
description: "Gateway SDK for TypeScript - A/B experiments, tracing, and observability",
|
|
2463
4121
|
main: "./dist/index.js",
|
|
2464
4122
|
module: "./dist/index.mjs",
|
|
@@ -2658,7 +4316,7 @@ var require_package = __commonJS({
|
|
|
2658
4316
|
});
|
|
2659
4317
|
|
|
2660
4318
|
// src/build/index.ts
|
|
2661
|
-
import { createHash as
|
|
4319
|
+
import { createHash as createHash3 } from "crypto";
|
|
2662
4320
|
function canonicalJson(value) {
|
|
2663
4321
|
if (value === null || typeof value !== "object") {
|
|
2664
4322
|
return JSON.stringify(value);
|
|
@@ -2670,7 +4328,7 @@ function canonicalJson(value) {
|
|
|
2670
4328
|
return `{${entries.map(([k, v]) => `${JSON.stringify(k)}:${canonicalJson(v)}`).join(",")}}`;
|
|
2671
4329
|
}
|
|
2672
4330
|
function sha256(text2) {
|
|
2673
|
-
return `sha256:${
|
|
4331
|
+
return `sha256:${createHash3("sha256").update(text2).digest("hex")}`;
|
|
2674
4332
|
}
|
|
2675
4333
|
function captureSource() {
|
|
2676
4334
|
const stack = new Error().stack?.split("\n") ?? [];
|
|
@@ -3065,7 +4723,7 @@ function buildProvider(config, logFn) {
|
|
|
3065
4723
|
const spanProcessors = [];
|
|
3066
4724
|
if (config.customSpanProcessors) {
|
|
3067
4725
|
for (const sp of config.customSpanProcessors) {
|
|
3068
|
-
spanProcessors.push(sp);
|
|
4726
|
+
spanProcessors.push(new SecretRedactingSpanProcessor(sp));
|
|
3069
4727
|
logFn(
|
|
3070
4728
|
"Added custom span processor: %s",
|
|
3071
4729
|
sp.constructor?.name ?? "unknown"
|
|
@@ -3084,7 +4742,11 @@ function buildProvider(config, logFn) {
|
|
|
3084
4742
|
if (config.batch?.maxExportBatchSize) {
|
|
3085
4743
|
batchConfig.maxExportBatchSize = config.batch.maxExportBatchSize;
|
|
3086
4744
|
}
|
|
3087
|
-
spanProcessors.push(
|
|
4745
|
+
spanProcessors.push(
|
|
4746
|
+
new SecretRedactingSpanProcessor(
|
|
4747
|
+
new BatchSpanProcessor(exporter, batchConfig)
|
|
4748
|
+
)
|
|
4749
|
+
);
|
|
3088
4750
|
let provider = new NodeTracerProvider({
|
|
3089
4751
|
resource: createResource(resourceAttrs)
|
|
3090
4752
|
});
|
|
@@ -3222,7 +4884,8 @@ var init_init = __esm({
|
|
|
3222
4884
|
"src/tracing/init.ts"() {
|
|
3223
4885
|
"use strict";
|
|
3224
4886
|
init_identity();
|
|
3225
|
-
|
|
4887
|
+
init_secrets();
|
|
4888
|
+
init_session();
|
|
3226
4889
|
init_scores();
|
|
3227
4890
|
init_build();
|
|
3228
4891
|
ENV_VARS = {
|
|
@@ -3378,7 +5041,7 @@ async function runTask(ref, agent, opts) {
|
|
|
3378
5041
|
let extra = {};
|
|
3379
5042
|
try {
|
|
3380
5043
|
const invoke = () => agent(taskRun);
|
|
3381
|
-
const result = traced ? await (await Promise.resolve().then(() => (
|
|
5044
|
+
const result = traced ? await (await Promise.resolve().then(() => (init_session(), session_exports))).withSession(runId, invoke) : await invoke();
|
|
3382
5045
|
({ report, extra } = reportFromResult(result));
|
|
3383
5046
|
} catch (error) {
|
|
3384
5047
|
const message = (error instanceof Error ? error.message : String(error)) || "Unknown error";
|
|
@@ -3451,7 +5114,7 @@ var init_taskRun = __esm({
|
|
|
3451
5114
|
"use strict";
|
|
3452
5115
|
init_browser();
|
|
3453
5116
|
init_evals();
|
|
3454
|
-
|
|
5117
|
+
init_session2();
|
|
3455
5118
|
init_taskSessions();
|
|
3456
5119
|
TaskRun = class {
|
|
3457
5120
|
constructor(runId, instruction, model, sessions2, manifest) {
|
|
@@ -3760,7 +5423,7 @@ var init_checkoutTarget = __esm({
|
|
|
3760
5423
|
});
|
|
3761
5424
|
|
|
3762
5425
|
// src/worlds/worldDir.ts
|
|
3763
|
-
import { createHash as
|
|
5426
|
+
import { createHash as createHash4 } from "crypto";
|
|
3764
5427
|
import * as fs3 from "fs";
|
|
3765
5428
|
import * as path3 from "path";
|
|
3766
5429
|
var WORLD_MANIFEST, API_BUNDLE_MANIFEST, BUNDLED_WORLD_PREFIX, CONNECTOR_SPEC, PYPROJECT, BENCHMARK_CONFIG, WORLD_SCHEMA_MARKERS, WORLD_ROOT_MARKERS, BROAD_ROOT_MARKERS, SKIPPED_DIRS, V1_DEP, V1_IMPORT, V1_TASKSET, HARBOR_TASK, skippedDir, byCodePoint, WorldDir;
|
|
@@ -3870,7 +5533,7 @@ var init_worldDir = __esm({
|
|
|
3870
5533
|
* sorted order: the version's identity, byte-compatible with
|
|
3871
5534
|
* `_archive.compute_content_hash` and Prime Intellect. */
|
|
3872
5535
|
get contentHash() {
|
|
3873
|
-
const hasher =
|
|
5536
|
+
const hasher = createHash4("sha256");
|
|
3874
5537
|
for (const rel of this.archivePaths) {
|
|
3875
5538
|
hasher.update(Buffer.from(`file:${rel}`, "utf-8"));
|
|
3876
5539
|
hasher.update(fs3.readFileSync(path3.join(this.dir, rel)));
|
|
@@ -4066,7 +5729,7 @@ __export(hub_exports, {
|
|
|
4066
5729
|
snapshotTreeHashes: () => snapshotTreeHashes,
|
|
4067
5730
|
writeLocalMeta: () => writeLocalMeta
|
|
4068
5731
|
});
|
|
4069
|
-
import { createHash as
|
|
5732
|
+
import { createHash as createHash5 } from "crypto";
|
|
4070
5733
|
import { gzipSync } from "zlib";
|
|
4071
5734
|
import * as fs5 from "fs";
|
|
4072
5735
|
import * as path5 from "path";
|
|
@@ -4178,7 +5841,7 @@ function writeLocalMeta(dir, meta) {
|
|
|
4178
5841
|
function snapshotTreeHashes(dir) {
|
|
4179
5842
|
const out = {};
|
|
4180
5843
|
for (const relPath of collectArchiveRelPaths(dir)) {
|
|
4181
|
-
out[relPath] =
|
|
5844
|
+
out[relPath] = createHash5("sha256").update(fs5.readFileSync(path5.join(dir, relPath))).digest("hex");
|
|
4182
5845
|
}
|
|
4183
5846
|
return out;
|
|
4184
5847
|
}
|
|
@@ -4224,7 +5887,7 @@ function buildFileManifest(dir) {
|
|
|
4224
5887
|
path: relPath,
|
|
4225
5888
|
isDirectory: false,
|
|
4226
5889
|
size: payload.length,
|
|
4227
|
-
sha256:
|
|
5890
|
+
sha256: createHash5("sha256").update(payload).digest("hex")
|
|
4228
5891
|
};
|
|
4229
5892
|
});
|
|
4230
5893
|
}
|
|
@@ -4449,7 +6112,7 @@ var init_hub = __esm({
|
|
|
4449
6112
|
tracked;
|
|
4450
6113
|
declared;
|
|
4451
6114
|
};
|
|
4452
|
-
sha256b64 = (data) =>
|
|
6115
|
+
sha256b64 = (data) => createHash5("sha256").update(data).digest("base64");
|
|
4453
6116
|
DetachedPushError = class extends Error {
|
|
4454
6117
|
constructor(dir, tag) {
|
|
4455
6118
|
super(
|
|
@@ -4650,6 +6313,34 @@ function parseSlugRef(slugRef) {
|
|
|
4650
6313
|
if (at === -1) return { slug: slugRef };
|
|
4651
6314
|
return { slug: slugRef.slice(0, at), ref: slugRef.slice(at + 1) };
|
|
4652
6315
|
}
|
|
6316
|
+
function rebaseConflicts(error) {
|
|
6317
|
+
if (!(error instanceof ApiError) || error.status !== 409) return null;
|
|
6318
|
+
let body;
|
|
6319
|
+
try {
|
|
6320
|
+
body = JSON.parse(error.text);
|
|
6321
|
+
} catch {
|
|
6322
|
+
return null;
|
|
6323
|
+
}
|
|
6324
|
+
const conflicts = body?.conflicts;
|
|
6325
|
+
if (!Array.isArray(conflicts)) return null;
|
|
6326
|
+
return conflicts.filter(isConflictPath).map(({ path: path16, reason }) => ({ path: path16, reason }));
|
|
6327
|
+
}
|
|
6328
|
+
function isConflictPath(value) {
|
|
6329
|
+
const entry = value;
|
|
6330
|
+
return typeof entry?.path === "string" && typeof entry.reason === "string";
|
|
6331
|
+
}
|
|
6332
|
+
function uncommittedPaths(error) {
|
|
6333
|
+
if (!(error instanceof ApiError) || error.status !== 409 || error.code !== "sandbox_uncommitted") return null;
|
|
6334
|
+
let body;
|
|
6335
|
+
try {
|
|
6336
|
+
body = JSON.parse(error.text);
|
|
6337
|
+
} catch {
|
|
6338
|
+
return null;
|
|
6339
|
+
}
|
|
6340
|
+
const uncommitted = body?.uncommitted;
|
|
6341
|
+
if (!Array.isArray(uncommitted)) return null;
|
|
6342
|
+
return uncommitted.filter((p) => typeof p === "string");
|
|
6343
|
+
}
|
|
4653
6344
|
function listQuery(filter) {
|
|
4654
6345
|
const params = new URLSearchParams();
|
|
4655
6346
|
if (filter.status) params.set("status", filter.status);
|
|
@@ -4658,18 +6349,25 @@ function listQuery(filter) {
|
|
|
4658
6349
|
const qs3 = params.toString();
|
|
4659
6350
|
return qs3 ? `?${qs3}` : "";
|
|
4660
6351
|
}
|
|
4661
|
-
var isSandboxImportPending, sid, WorldSandboxClient;
|
|
6352
|
+
var isSandboxImportPending, sid, SANDBOXES, SANDBOX_REQUEST_TIMEOUT_MS, WorldSandboxClient;
|
|
4662
6353
|
var init_sandbox = __esm({
|
|
4663
6354
|
"src/worlds/sandbox.ts"() {
|
|
4664
6355
|
"use strict";
|
|
4665
6356
|
init_worlds();
|
|
4666
6357
|
isSandboxImportPending = (answer) => !("versionId" in answer);
|
|
4667
6358
|
sid = encodeURIComponent;
|
|
6359
|
+
SANDBOXES = "/api/public/benchmark-containers/sandboxes";
|
|
6360
|
+
SANDBOX_REQUEST_TIMEOUT_MS = 66e4;
|
|
4668
6361
|
WorldSandboxClient = class {
|
|
4669
6362
|
constructor(options = {}) {
|
|
4670
6363
|
this.options = options;
|
|
4671
6364
|
}
|
|
4672
6365
|
options;
|
|
6366
|
+
request(method, path16, body) {
|
|
6367
|
+
return apiRequest(this.options, method, path16, body, {
|
|
6368
|
+
timeoutMs: SANDBOX_REQUEST_TIMEOUT_MS
|
|
6369
|
+
});
|
|
6370
|
+
}
|
|
4673
6371
|
/**
|
|
4674
6372
|
* `{ slug, ref? }` opens a READY version; `{ new, from }` opens a sandbox on
|
|
4675
6373
|
* a world that does not exist yet (409 `world_exists` if the slug is taken,
|
|
@@ -4677,42 +6375,39 @@ var init_sandbox = __esm({
|
|
|
4677
6375
|
* creates the world on `main`.
|
|
4678
6376
|
*/
|
|
4679
6377
|
open(target) {
|
|
4680
|
-
return
|
|
6378
|
+
return this.request("POST", `${SANDBOXES}`, target);
|
|
4681
6379
|
}
|
|
4682
6380
|
status(sandboxId) {
|
|
4683
|
-
return
|
|
6381
|
+
return this.request("GET", `${SANDBOXES}/${sid(sandboxId)}`);
|
|
4684
6382
|
}
|
|
4685
6383
|
/** The project's sandboxes, newest first — how an agent finds one it left open. */
|
|
4686
6384
|
async list(filter = {}) {
|
|
4687
|
-
const res = await
|
|
4688
|
-
this.options,
|
|
4689
|
-
"GET",
|
|
4690
|
-
`/api/public/benchmark-containers/sandboxes${listQuery(filter)}`
|
|
4691
|
-
);
|
|
6385
|
+
const res = await this.request("GET", `${SANDBOXES}${listQuery(filter)}`);
|
|
4692
6386
|
return res.sandboxes;
|
|
4693
6387
|
}
|
|
4694
6388
|
async read(sandboxId, filePath) {
|
|
4695
|
-
const res = await
|
|
4696
|
-
this.options,
|
|
6389
|
+
const res = await this.request(
|
|
4697
6390
|
"GET",
|
|
4698
|
-
|
|
6391
|
+
`${SANDBOXES}/${sid(sandboxId)}/file?path=${encodeURIComponent(filePath)}`
|
|
4699
6392
|
);
|
|
4700
6393
|
return { path: res.path, size: res.size, bytes: Buffer.from(res.contentBase64, "base64") };
|
|
4701
6394
|
}
|
|
4702
6395
|
write(sandboxId, filePath, bytes) {
|
|
4703
|
-
return
|
|
6396
|
+
return this.request("PUT", `${SANDBOXES}/${sid(sandboxId)}/file`, {
|
|
4704
6397
|
path: filePath,
|
|
4705
6398
|
contentBase64: bytes.toString("base64")
|
|
4706
6399
|
});
|
|
4707
6400
|
}
|
|
4708
6401
|
exec(sandboxId, input) {
|
|
4709
|
-
return
|
|
6402
|
+
return this.request("POST", `${SANDBOXES}/${sid(sandboxId)}/exec`, input);
|
|
4710
6403
|
}
|
|
4711
6404
|
check(sandboxId) {
|
|
4712
|
-
return
|
|
6405
|
+
return this.request("POST", `${SANDBOXES}/${sid(sandboxId)}/check`, {});
|
|
4713
6406
|
}
|
|
6407
|
+
/** With `rebase`, a moved base is replayed onto; a 409 then names the conflicting paths (`rebaseConflicts`). */
|
|
4714
6408
|
commit(sandboxId, input) {
|
|
4715
|
-
|
|
6409
|
+
const { rebase, ...rest } = input;
|
|
6410
|
+
return this.request("POST", `${SANDBOXES}/${sid(sandboxId)}/commit`, rebase ? { ...rest, rebase: true } : rest);
|
|
4716
6411
|
}
|
|
4717
6412
|
/**
|
|
4718
6413
|
* A rows file already in the sandbox tree into the PLATFORM world the
|
|
@@ -4721,10 +6416,11 @@ var init_sandbox = __esm({
|
|
|
4721
6416
|
* tree and never carries data.
|
|
4722
6417
|
*/
|
|
4723
6418
|
importData(sandboxId, input) {
|
|
4724
|
-
return
|
|
6419
|
+
return this.request("POST", `${SANDBOXES}/${sid(sandboxId)}/import`, input);
|
|
4725
6420
|
}
|
|
4726
|
-
|
|
4727
|
-
|
|
6421
|
+
/** Uncommitted work is a 409 (`uncommittedPaths`) unless `force` discards it. */
|
|
6422
|
+
close(sandboxId, opts = {}) {
|
|
6423
|
+
return this.request("DELETE", `${SANDBOXES}/${sid(sandboxId)}`, opts.force ? { force: true } : void 0);
|
|
4728
6424
|
}
|
|
4729
6425
|
};
|
|
4730
6426
|
}
|
|
@@ -5043,7 +6739,7 @@ var init_json = __esm({
|
|
|
5043
6739
|
});
|
|
5044
6740
|
|
|
5045
6741
|
// src/worlds/transforms.ts
|
|
5046
|
-
import { createHash as
|
|
6742
|
+
import { createHash as createHash6 } from "crypto";
|
|
5047
6743
|
function parseTransform(name) {
|
|
5048
6744
|
const simple = Object.prototype.hasOwnProperty.call(SIMPLE, name) ? SIMPLE[name] : void 0;
|
|
5049
6745
|
if (simple) return simple;
|
|
@@ -5081,7 +6777,7 @@ var init_transforms = __esm({
|
|
|
5081
6777
|
return at === -1 ? "" : value.slice(at + 1).toLowerCase();
|
|
5082
6778
|
};
|
|
5083
6779
|
stripPrefix = (prefix) => (value) => value.startsWith(prefix) ? value.slice(prefix.length) : value;
|
|
5084
|
-
hex = (algorithm, value) =>
|
|
6780
|
+
hex = (algorithm, value) => createHash6(algorithm).update(value, "utf8").digest("hex");
|
|
5085
6781
|
SIMPLE = {
|
|
5086
6782
|
lower: (value) => value.toLowerCase(),
|
|
5087
6783
|
upper: (value) => value.toUpperCase(),
|
|
@@ -5105,7 +6801,7 @@ var init_transforms = __esm({
|
|
|
5105
6801
|
});
|
|
5106
6802
|
|
|
5107
6803
|
// src/worlds/redaction.ts
|
|
5108
|
-
import { createHash as
|
|
6804
|
+
import { createHash as createHash7 } from "crypto";
|
|
5109
6805
|
function pyText(value) {
|
|
5110
6806
|
if (typeof value === "string") return value;
|
|
5111
6807
|
if (Number.isInteger(value)) return String(value);
|
|
@@ -5114,7 +6810,7 @@ function pyText(value) {
|
|
|
5114
6810
|
return pyFloatRepr(value);
|
|
5115
6811
|
}
|
|
5116
6812
|
function hashForm(slug, plaintext) {
|
|
5117
|
-
return "sha256:" +
|
|
6813
|
+
return "sha256:" + createHash7("sha256").update(`${slug}:${pyText(plaintext)}`, "utf8").digest("hex");
|
|
5118
6814
|
}
|
|
5119
6815
|
function preserveForm(slug, plaintext) {
|
|
5120
6816
|
const kind = typeof plaintext === "string" ? "str" : isInt(plaintext) ? "int" : "float";
|
|
@@ -5123,12 +6819,12 @@ function preserveForm(slug, plaintext) {
|
|
|
5123
6819
|
}
|
|
5124
6820
|
function shapeText(slug, text2, kind) {
|
|
5125
6821
|
const seed = Buffer.from(`${slug}:${text2}`, "utf8");
|
|
5126
|
-
let digest =
|
|
6822
|
+
let digest = createHash7("sha256").update(seed).digest();
|
|
5127
6823
|
let cursor = 0;
|
|
5128
6824
|
const out = [];
|
|
5129
6825
|
for (const char of text2) {
|
|
5130
6826
|
if (cursor === digest.length) {
|
|
5131
|
-
digest =
|
|
6827
|
+
digest = createHash7("sha256").update(Buffer.concat([digest, seed])).digest();
|
|
5132
6828
|
cursor = 0;
|
|
5133
6829
|
}
|
|
5134
6830
|
const byte = digest[cursor];
|
|
@@ -5256,48 +6952,19 @@ var init_router = __esm({
|
|
|
5256
6952
|
import * as fs6 from "fs";
|
|
5257
6953
|
import * as os from "os";
|
|
5258
6954
|
import * as path6 from "path";
|
|
5259
|
-
function transportDetail(error, timeoutMs) {
|
|
5260
|
-
if (error instanceof Error && error.name === "AbortError") return `timed out after ${Math.round(timeoutMs / 1e3)}s`;
|
|
5261
|
-
const cause = error instanceof Error && error.cause instanceof Error ? error.cause : void 0;
|
|
5262
|
-
const code = cause && "code" in cause && typeof cause.code === "string" ? `${cause.code}: ` : "";
|
|
5263
|
-
const message = cause?.message ?? (error instanceof Error ? error.message : String(error));
|
|
5264
|
-
return `${code}${message}`;
|
|
5265
|
-
}
|
|
5266
6955
|
async function api(creds, method, route, body, init3 = {}) {
|
|
5267
|
-
const
|
|
5268
|
-
|
|
5269
|
-
|
|
5270
|
-
let res;
|
|
5271
|
-
try {
|
|
5272
|
-
res = await fetch(`${creds.host}${route}`, {
|
|
5273
|
-
method,
|
|
5274
|
-
headers: {
|
|
5275
|
-
"content-type": "application/json",
|
|
5276
|
-
accept: "application/json",
|
|
5277
|
-
authorization: "Basic " + Buffer.from(`${creds.publicKey}:${creds.secretKey}`).toString("base64")
|
|
5278
|
-
},
|
|
5279
|
-
...body === void 0 ? {} : { body: JSON.stringify(body) },
|
|
5280
|
-
signal: controller.signal
|
|
5281
|
-
});
|
|
5282
|
-
} catch (error) {
|
|
5283
|
-
clearTimeout(timer);
|
|
5284
|
-
throw new UnreachableError(creds.host, method, route, transportDetail(error, timeoutMs));
|
|
5285
|
-
}
|
|
5286
|
-
try {
|
|
5287
|
-
const text2 = await res.text();
|
|
5288
|
-
if (!res.ok) throw new ApiError(res.status, method, route, text2);
|
|
5289
|
-
return text2 ? JSON.parse(text2) : {};
|
|
5290
|
-
} finally {
|
|
5291
|
-
clearTimeout(timer);
|
|
5292
|
-
}
|
|
6956
|
+
const reply = await new PlatformTransport(creds).send(method, route, body, init3);
|
|
6957
|
+
if (!reply.ok) throw new ApiError2(reply.status, method, route, reply.text);
|
|
6958
|
+
return reply.text ? JSON.parse(reply.text) : {};
|
|
5293
6959
|
}
|
|
5294
|
-
var
|
|
6960
|
+
var ApiError2;
|
|
5295
6961
|
var init_config = __esm({
|
|
5296
6962
|
"src/cli/config.ts"() {
|
|
5297
6963
|
"use strict";
|
|
5298
6964
|
init_router();
|
|
5299
6965
|
init_worlds();
|
|
5300
|
-
|
|
6966
|
+
init_transport();
|
|
6967
|
+
ApiError2 = class extends CliError {
|
|
5301
6968
|
constructor(status, method, route, text2) {
|
|
5302
6969
|
const body = parseErrorBody(text2);
|
|
5303
6970
|
super(`${method} ${route} -> ${status}: ${body.detail}`, 1);
|
|
@@ -5313,19 +6980,6 @@ var init_config = __esm({
|
|
|
5313
6980
|
text;
|
|
5314
6981
|
code;
|
|
5315
6982
|
};
|
|
5316
|
-
UnreachableError = class extends CliError {
|
|
5317
|
-
constructor(host, method, route, detail) {
|
|
5318
|
-
super(`${method} ${route}: no answer from ${host} (${detail}). Check the host and the network, then retry.`, 1);
|
|
5319
|
-
this.host = host;
|
|
5320
|
-
this.method = method;
|
|
5321
|
-
this.route = route;
|
|
5322
|
-
this.detail = detail;
|
|
5323
|
-
}
|
|
5324
|
-
host;
|
|
5325
|
-
method;
|
|
5326
|
-
route;
|
|
5327
|
-
detail;
|
|
5328
|
-
};
|
|
5329
6983
|
}
|
|
5330
6984
|
});
|
|
5331
6985
|
|
|
@@ -5504,7 +7158,7 @@ var init_local = __esm({
|
|
|
5504
7158
|
"use strict";
|
|
5505
7159
|
init_router();
|
|
5506
7160
|
init_config();
|
|
5507
|
-
MIN_PYTHON = [3,
|
|
7161
|
+
MIN_PYTHON = [3, 12];
|
|
5508
7162
|
DIAGNOSTIC_TAIL = 600;
|
|
5509
7163
|
BRIDGE_BOOTSTRAP = `import sys,runpy,types,os
|
|
5510
7164
|
root=sys.argv[1]
|
|
@@ -5516,7 +7170,6 @@ runpy.run_module('gatewaysdk.environment.schema.platform',run_name='__main__')`;
|
|
|
5516
7170
|
PYTHON_CANDIDATES = [
|
|
5517
7171
|
"python3.13",
|
|
5518
7172
|
"python3.12",
|
|
5519
|
-
"python3.11",
|
|
5520
7173
|
"python3",
|
|
5521
7174
|
"python"
|
|
5522
7175
|
];
|
|
@@ -5628,53 +7281,41 @@ function runsLocally(request) {
|
|
|
5628
7281
|
async function runtime(creds, request, opts = {}) {
|
|
5629
7282
|
const local = localRuntime();
|
|
5630
7283
|
if (local && runsLocally(request)) {
|
|
5631
|
-
const
|
|
5632
|
-
const
|
|
5633
|
-
if (
|
|
5634
|
-
return
|
|
7284
|
+
const payload2 = await localBridge(request, local, opts);
|
|
7285
|
+
const detail2 = detailFrom(payload2);
|
|
7286
|
+
if (detail2) throw new BridgeRejected(detail2);
|
|
7287
|
+
return payload2;
|
|
5635
7288
|
}
|
|
5636
7289
|
if (!creds)
|
|
5637
7290
|
throw new CliError(
|
|
5638
7291
|
"This needs the schema runtime (the CLI bundles it) or platform credentials (`gateway auth login`). " + localRuntimeReason()
|
|
5639
7292
|
);
|
|
5640
|
-
const controller = new AbortController();
|
|
5641
|
-
const timer = setTimeout(() => controller.abort(), opts.timeoutMs ?? 18e4);
|
|
5642
7293
|
const route = "/api/public/worlds/runtime";
|
|
7294
|
+
const res = await new PlatformTransport(creds).send("POST", route, request, {
|
|
7295
|
+
timeoutMs: opts.timeoutMs ?? RUNTIME_TIMEOUT_MS
|
|
7296
|
+
});
|
|
7297
|
+
let payload = null;
|
|
5643
7298
|
try {
|
|
5644
|
-
|
|
5645
|
-
|
|
5646
|
-
|
|
5647
|
-
"content-type": "application/json",
|
|
5648
|
-
accept: "application/json",
|
|
5649
|
-
authorization: "Basic " + Buffer.from(`${creds.publicKey}:${creds.secretKey}`).toString("base64")
|
|
5650
|
-
},
|
|
5651
|
-
body: JSON.stringify(request),
|
|
5652
|
-
signal: controller.signal
|
|
5653
|
-
});
|
|
5654
|
-
const text2 = await res.text();
|
|
5655
|
-
let payload = null;
|
|
5656
|
-
try {
|
|
5657
|
-
payload = text2 ? JSON.parse(text2) : {};
|
|
5658
|
-
} catch {
|
|
5659
|
-
payload = null;
|
|
5660
|
-
}
|
|
5661
|
-
const detail = detailFrom(payload);
|
|
5662
|
-
if (detail) throw new BridgeRejected(detail);
|
|
5663
|
-
if (!res.ok)
|
|
5664
|
-
throw new CliError(`POST ${route} (${request.command}) -> ${res.status}: ${text2.slice(0, 600)}`, 1);
|
|
5665
|
-
if (payload === null) throw new CliError(`POST ${route} (${request.command}) returned non-JSON`, 1);
|
|
5666
|
-
return payload;
|
|
5667
|
-
} finally {
|
|
5668
|
-
clearTimeout(timer);
|
|
7299
|
+
payload = res.text ? JSON.parse(res.text) : {};
|
|
7300
|
+
} catch {
|
|
7301
|
+
payload = null;
|
|
5669
7302
|
}
|
|
7303
|
+
const detail = detailFrom(payload);
|
|
7304
|
+
if (detail) throw new BridgeRejected(detail);
|
|
7305
|
+
if (!res.ok)
|
|
7306
|
+
throw new CliError(`POST ${route} (${request.command}) -> ${res.status}: ${res.text.slice(0, 600)}`, 1);
|
|
7307
|
+
if (payload === null) throw new CliError(`POST ${route} (${request.command}) returned non-JSON`, 1);
|
|
7308
|
+
return payload;
|
|
5670
7309
|
}
|
|
5671
|
-
var MAX_WORLD_FILES, SKIP_DIRS, BUILD_OUTPUT, BridgeRejected, YAML_NAME;
|
|
7310
|
+
var MAX_WORLD_FILES, RUNTIME_TIMEOUT_MS, SKIP_DIRS, BUILD_OUTPUT, BridgeRejected, YAML_NAME;
|
|
5672
7311
|
var init_client = __esm({
|
|
5673
7312
|
"src/cli/runtime/client.ts"() {
|
|
5674
7313
|
"use strict";
|
|
5675
7314
|
init_router();
|
|
5676
7315
|
init_local();
|
|
7316
|
+
init_transport();
|
|
5677
7317
|
MAX_WORLD_FILES = 2e3;
|
|
7318
|
+
RUNTIME_TIMEOUT_MS = 18e4;
|
|
5678
7319
|
SKIP_DIRS = /* @__PURE__ */ new Set(["__pycache__", ".git", "node_modules", ".gateway"]);
|
|
5679
7320
|
BUILD_OUTPUT = /(^|\/)state\.(sqlite|json)$/;
|
|
5680
7321
|
BridgeRejected = class extends CliError {
|
|
@@ -6082,7 +7723,7 @@ if (fn) {
|
|
|
6082
7723
|
});
|
|
6083
7724
|
|
|
6084
7725
|
// src/cli/platform/worldData/batches.ts
|
|
6085
|
-
import { createHash as
|
|
7726
|
+
import { createHash as createHash8 } from "crypto";
|
|
6086
7727
|
import * as fs11 from "fs";
|
|
6087
7728
|
function isSettled(status) {
|
|
6088
7729
|
if (!TERMINAL_STATES.has(status.state)) return false;
|
|
@@ -6093,7 +7734,7 @@ function uploadHeadersFor(gz) {
|
|
|
6093
7734
|
return {
|
|
6094
7735
|
"content-type": "application/gzip",
|
|
6095
7736
|
"content-length": String(gz.length),
|
|
6096
|
-
"x-amz-checksum-sha256":
|
|
7737
|
+
"x-amz-checksum-sha256": createHash8("sha256").update(gz).digest("base64")
|
|
6097
7738
|
};
|
|
6098
7739
|
}
|
|
6099
7740
|
async function forEachLimited(items, limit, fn) {
|
|
@@ -6296,7 +7937,7 @@ var init_batches = __esm({
|
|
|
6296
7937
|
});
|
|
6297
7938
|
|
|
6298
7939
|
// src/cli/platform/worldData/chunker.ts
|
|
6299
|
-
import { createHash as
|
|
7940
|
+
import { createHash as createHash9 } from "crypto";
|
|
6300
7941
|
import { deflateRawSync } from "zlib";
|
|
6301
7942
|
function chunkLine(row, declared) {
|
|
6302
7943
|
if (declared !== null) return dumps(row.row) + "\n";
|
|
@@ -6337,12 +7978,12 @@ function finishChunk(ordinal, raw, rows, entity, firstRow = 0) {
|
|
|
6337
7978
|
const gz = gzipDeterministic(raw, { name: chunkName(ordinal) });
|
|
6338
7979
|
return {
|
|
6339
7980
|
ordinal,
|
|
6340
|
-
digest:
|
|
7981
|
+
digest: createHash9("sha256").update(gz).digest("hex"),
|
|
6341
7982
|
bytes: gz.length,
|
|
6342
7983
|
rows,
|
|
6343
7984
|
entity,
|
|
6344
7985
|
rawBytes: raw.length,
|
|
6345
|
-
contentSha256:
|
|
7986
|
+
contentSha256: createHash9("sha256").update(raw).digest("hex"),
|
|
6346
7987
|
firstRow,
|
|
6347
7988
|
gz
|
|
6348
7989
|
};
|
|
@@ -6679,7 +8320,7 @@ var init_ingest = __esm({
|
|
|
6679
8320
|
});
|
|
6680
8321
|
|
|
6681
8322
|
// src/worlds/editSessions.ts
|
|
6682
|
-
var WORLDS, WorldEditClient;
|
|
8323
|
+
var WORLDS, WorldEditClient, TASK_EDITS, TaskEditClient;
|
|
6683
8324
|
var init_editSessions = __esm({
|
|
6684
8325
|
"src/worlds/editSessions.ts"() {
|
|
6685
8326
|
"use strict";
|
|
@@ -6711,6 +8352,22 @@ var init_editSessions = __esm({
|
|
|
6711
8352
|
return apiRequest(this.options, "POST", `${WORLDS}/${encodeURIComponent(slug)}/edits/rollback`, input);
|
|
6712
8353
|
}
|
|
6713
8354
|
};
|
|
8355
|
+
TASK_EDITS = "/api/public/world-task-edits";
|
|
8356
|
+
TaskEditClient = class {
|
|
8357
|
+
constructor(options = {}) {
|
|
8358
|
+
this.options = options;
|
|
8359
|
+
}
|
|
8360
|
+
options;
|
|
8361
|
+
status(task) {
|
|
8362
|
+
return apiRequest(this.options, "POST", `${TASK_EDITS}/status`, { task });
|
|
8363
|
+
}
|
|
8364
|
+
close(task, input = {}) {
|
|
8365
|
+
return apiRequest(this.options, "POST", `${TASK_EDITS}/close`, { task, ...input });
|
|
8366
|
+
}
|
|
8367
|
+
rollback(task, input) {
|
|
8368
|
+
return apiRequest(this.options, "POST", `${TASK_EDITS}/rollback`, { task, ...input });
|
|
8369
|
+
}
|
|
8370
|
+
};
|
|
6714
8371
|
}
|
|
6715
8372
|
});
|
|
6716
8373
|
|
|
@@ -6806,7 +8463,11 @@ var init_dryRun = __esm({
|
|
|
6806
8463
|
// src/worlds/index.ts
|
|
6807
8464
|
var worlds_exports = {};
|
|
6808
8465
|
__export(worlds_exports, {
|
|
6809
|
-
|
|
8466
|
+
ACTION_NAMES: () => ACTION_NAMES,
|
|
8467
|
+
ActionTracer: () => ActionTracer,
|
|
8468
|
+
AnthropicComputer: () => AnthropicComputer,
|
|
8469
|
+
AnthropicComputer20251124: () => AnthropicComputer20251124,
|
|
8470
|
+
ApiError: () => ApiError,
|
|
6810
8471
|
BROWSER_GONE_PATTERNS: () => BROWSER_GONE_PATTERNS,
|
|
6811
8472
|
BROWSER_TIERS: () => BROWSER_TIERS,
|
|
6812
8473
|
BrowserActionRecorder: () => BrowserActionRecorder,
|
|
@@ -6817,11 +8478,13 @@ __export(worlds_exports, {
|
|
|
6817
8478
|
CALL_BODY_LIMIT_LABEL: () => CALL_BODY_LIMIT_LABEL,
|
|
6818
8479
|
COMPUTER_USE_SPECS: () => COMPUTER_USE_SPECS,
|
|
6819
8480
|
CheckoutProvenance: () => CheckoutProvenance,
|
|
8481
|
+
ComputerAction: () => ComputerAction,
|
|
6820
8482
|
DEFAULT_BRANCH: () => DEFAULT_BRANCH,
|
|
6821
8483
|
DEFAULT_VIEWPORT: () => DEFAULT_VIEWPORT,
|
|
6822
8484
|
DRY_RUN_AGENT: () => DRY_RUN_AGENT,
|
|
6823
8485
|
DRY_RUN_KIND: () => DRY_RUN_KIND,
|
|
6824
8486
|
DetachedPushError: () => DetachedPushError,
|
|
8487
|
+
Display: () => Display,
|
|
6825
8488
|
DryRunOutcome: () => DryRunOutcome,
|
|
6826
8489
|
EVENT_BATCH_SIZE: () => EVENT_BATCH_SIZE,
|
|
6827
8490
|
EVENT_FLUSH_INTERVAL_MS: () => EVENT_FLUSH_INTERVAL_MS,
|
|
@@ -6831,17 +8494,34 @@ __export(worlds_exports, {
|
|
|
6831
8494
|
GatewayEvalsClient: () => GatewayEvalsClient,
|
|
6832
8495
|
HostedDryRunClient: () => HostedDryRunClient,
|
|
6833
8496
|
IDLE_WARNING_MINUTES: () => IDLE_WARNING_MINUTES,
|
|
8497
|
+
KEY_NAMES: () => KEY_NAMES,
|
|
8498
|
+
KeyChord: () => KeyChord,
|
|
8499
|
+
NOT_EXECUTED: () => NOT_EXECUTED,
|
|
6834
8500
|
NO_GRADER_REASON: () => NO_GRADER_REASON,
|
|
8501
|
+
NativeComputer: () => NativeComputer,
|
|
8502
|
+
OpenAIComputer: () => OpenAIComputer,
|
|
8503
|
+
OpenAIPreviewComputer: () => OpenAIPreviewComputer,
|
|
8504
|
+
PLATFORM_TIMEOUT_DEFAULT_MS: () => PLATFORM_TIMEOUT_DEFAULT_MS,
|
|
8505
|
+
PLATFORM_TIMEOUT_ENV: () => PLATFORM_TIMEOUT_ENV,
|
|
8506
|
+
PendingSafetyChecks: () => PendingSafetyChecks,
|
|
8507
|
+
PlatformTransport: () => PlatformTransport,
|
|
6835
8508
|
PushSlugConflict: () => PushSlugConflict,
|
|
6836
8509
|
RECOVER_BUDGET_MS: () => RECOVER_BUDGET_MS,
|
|
8510
|
+
SANDBOX_REQUEST_TIMEOUT_MS: () => SANDBOX_REQUEST_TIMEOUT_MS,
|
|
8511
|
+
SECRET_KEY: () => SECRET_KEY,
|
|
6837
8512
|
SESSION_STATES: () => SESSION_STATES,
|
|
8513
|
+
SPAN_PREFIX: () => SPAN_PREFIX,
|
|
6838
8514
|
STATUS_WAIT_CAP_SECONDS: () => STATUS_WAIT_CAP_SECONDS,
|
|
6839
8515
|
STRIP_PREFIX: () => STRIP_PREFIX,
|
|
6840
8516
|
SURFACE_KINDS: () => SURFACE_KINDS,
|
|
8517
|
+
Screen: () => Screen,
|
|
6841
8518
|
SecretScrubber: () => SecretScrubber,
|
|
6842
8519
|
TRANSFORMS: () => TRANSFORMS,
|
|
8520
|
+
TaskEditClient: () => TaskEditClient,
|
|
6843
8521
|
TaskRun: () => TaskRun,
|
|
6844
8522
|
TaskSessions: () => TaskSessions,
|
|
8523
|
+
TransportCause: () => TransportCause,
|
|
8524
|
+
UnreachableError: () => UnreachableError,
|
|
6845
8525
|
VERIFIER_REWARD_PREFIX: () => VERIFIER_REWARD_PREFIX,
|
|
6846
8526
|
WHITESPACE: () => WHITESPACE,
|
|
6847
8527
|
WorldBrowser: () => WorldBrowser,
|
|
@@ -6909,6 +8589,8 @@ __export(worlds_exports, {
|
|
|
6909
8589
|
parseToolCallRecord: () => parseToolCallRecord,
|
|
6910
8590
|
parseTransform: () => parseTransform,
|
|
6911
8591
|
parseWorldTaskRefs: () => parseWorldTaskRefs,
|
|
8592
|
+
platformTimeoutMs: () => platformTimeoutMs,
|
|
8593
|
+
playwrightKey: () => playwrightKey,
|
|
6912
8594
|
preserveForm: () => preserveForm,
|
|
6913
8595
|
propose: () => propose,
|
|
6914
8596
|
pull: () => pull,
|
|
@@ -6918,8 +8600,10 @@ __export(worlds_exports, {
|
|
|
6918
8600
|
pyText: () => pyText,
|
|
6919
8601
|
queryRows: () => queryRows,
|
|
6920
8602
|
queryRowsSearch: () => queryRowsSearch,
|
|
8603
|
+
readField: () => readField,
|
|
6921
8604
|
readLocalMeta: () => readLocalMeta,
|
|
6922
8605
|
readToolCallRecords: () => readToolCallRecords,
|
|
8606
|
+
rebaseConflicts: () => rebaseConflicts,
|
|
6923
8607
|
redactActionArgs: () => redactActionArgs,
|
|
6924
8608
|
redactionOf: () => redactionOf,
|
|
6925
8609
|
releaseConnection: () => releaseConnection,
|
|
@@ -6942,6 +8626,7 @@ __export(worlds_exports, {
|
|
|
6942
8626
|
toolCallsFromObservations: () => toolCallsFromObservations,
|
|
6943
8627
|
uiEntryUrl: () => uiEntryUrl,
|
|
6944
8628
|
uiUrl: () => uiUrl,
|
|
8629
|
+
uncommittedPaths: () => uncommittedPaths,
|
|
6945
8630
|
updateTask: () => updateTask,
|
|
6946
8631
|
upsertRunConfig: () => upsertRunConfig,
|
|
6947
8632
|
validateTask: () => validateTask,
|
|
@@ -6980,19 +8665,10 @@ function parseErrorBody(text2, limit = 600) {
|
|
|
6980
8665
|
code: stableCode
|
|
6981
8666
|
};
|
|
6982
8667
|
}
|
|
6983
|
-
async function apiRequest(options, method, path16, body) {
|
|
6984
|
-
const
|
|
6985
|
-
|
|
6986
|
-
|
|
6987
|
-
headers: {
|
|
6988
|
-
"content-type": "application/json",
|
|
6989
|
-
authorization: "Basic " + Buffer.from(`${publicKey}:${secretKey}`).toString("base64")
|
|
6990
|
-
},
|
|
6991
|
-
...body === void 0 ? {} : { body: JSON.stringify(body) }
|
|
6992
|
-
});
|
|
6993
|
-
const text2 = await res.text();
|
|
6994
|
-
if (!res.ok) throw new ApiError2(res.status, method, path16, text2);
|
|
6995
|
-
return JSON.parse(text2);
|
|
8668
|
+
async function apiRequest(options, method, path16, body, init3 = {}) {
|
|
8669
|
+
const reply = await new PlatformTransport(resolveEnv(options)).send(method, path16, body, init3);
|
|
8670
|
+
if (!reply.ok) throw new ApiError(reply.status, method, path16, reply.text);
|
|
8671
|
+
return JSON.parse(reply.text);
|
|
6996
8672
|
}
|
|
6997
8673
|
async function setEnvSecret(slug, key2, value, options = {}) {
|
|
6998
8674
|
return apiRequest(
|
|
@@ -7168,11 +8844,13 @@ async function resolveWorld(slugRef, slug, ref, pin, options) {
|
|
|
7168
8844
|
}
|
|
7169
8845
|
return world;
|
|
7170
8846
|
}
|
|
7171
|
-
var
|
|
8847
|
+
var ApiError, WorldTask, WorldSet;
|
|
7172
8848
|
var init_worlds = __esm({
|
|
7173
8849
|
"src/worlds/index.ts"() {
|
|
7174
8850
|
"use strict";
|
|
7175
|
-
|
|
8851
|
+
init_transport();
|
|
8852
|
+
init_transport();
|
|
8853
|
+
init_session2();
|
|
7176
8854
|
init_sessionList();
|
|
7177
8855
|
init_sessionContract();
|
|
7178
8856
|
init_taskRef();
|
|
@@ -7184,6 +8862,7 @@ var init_worlds = __esm({
|
|
|
7184
8862
|
init_evals();
|
|
7185
8863
|
init_browser();
|
|
7186
8864
|
init_browserReconnect();
|
|
8865
|
+
init_nativeComputer();
|
|
7187
8866
|
init_hub();
|
|
7188
8867
|
init_validate();
|
|
7189
8868
|
init_describe();
|
|
@@ -7195,15 +8874,17 @@ var init_worlds = __esm({
|
|
|
7195
8874
|
init_sandbox();
|
|
7196
8875
|
init_editSessions();
|
|
7197
8876
|
init_dryRun();
|
|
7198
|
-
|
|
7199
|
-
constructor(status, method, path16,
|
|
7200
|
-
const parsed = parseErrorBody(
|
|
8877
|
+
ApiError = class extends Error {
|
|
8878
|
+
constructor(status, method, path16, text2) {
|
|
8879
|
+
const parsed = parseErrorBody(text2);
|
|
7201
8880
|
super(`${method} ${path16} -> ${status}: ${parsed.detail}`);
|
|
7202
8881
|
this.status = status;
|
|
8882
|
+
this.text = text2;
|
|
7203
8883
|
this.name = "ApiError";
|
|
7204
8884
|
this.code = parsed.code;
|
|
7205
8885
|
}
|
|
7206
8886
|
status;
|
|
8887
|
+
text;
|
|
7207
8888
|
code;
|
|
7208
8889
|
};
|
|
7209
8890
|
WorldTask = class {
|
|
@@ -7248,7 +8929,7 @@ var init_worlds = __esm({
|
|
|
7248
8929
|
* worlds/session.ts.
|
|
7249
8930
|
*/
|
|
7250
8931
|
async open(task, opts = {}) {
|
|
7251
|
-
const { openSession: openSession2 } = await Promise.resolve().then(() => (
|
|
8932
|
+
const { openSession: openSession2 } = await Promise.resolve().then(() => (init_session2(), session_exports2));
|
|
7252
8933
|
return openSession2(this.slug, {
|
|
7253
8934
|
task,
|
|
7254
8935
|
versionId: this.version.versionId,
|
|
@@ -9673,7 +11354,7 @@ var gateway = {
|
|
|
9673
11354
|
init_users();
|
|
9674
11355
|
init_scores();
|
|
9675
11356
|
init_worlds();
|
|
9676
|
-
|
|
11357
|
+
init_session2();
|
|
9677
11358
|
|
|
9678
11359
|
// src/files/index.ts
|
|
9679
11360
|
var files_exports = {};
|
|
@@ -9700,7 +11381,7 @@ __export(files_exports, {
|
|
|
9700
11381
|
uploadFile: () => uploadFile
|
|
9701
11382
|
});
|
|
9702
11383
|
init_worlds();
|
|
9703
|
-
import { createHash as
|
|
11384
|
+
import { createHash as createHash10 } from "crypto";
|
|
9704
11385
|
import * as fs13 from "fs";
|
|
9705
11386
|
import * as path12 from "path";
|
|
9706
11387
|
import { Readable, Transform } from "stream";
|
|
@@ -9765,7 +11446,7 @@ async function confirmUpload(options = {}, fileId, ok = true) {
|
|
|
9765
11446
|
return apiRequest(options, "POST", `${BASE}/confirm`, { fileId, ok });
|
|
9766
11447
|
}
|
|
9767
11448
|
async function sha256Base64(localPath) {
|
|
9768
|
-
const hash =
|
|
11449
|
+
const hash = createHash10("sha256");
|
|
9769
11450
|
for await (const chunk of fs13.createReadStream(localPath)) hash.update(chunk);
|
|
9770
11451
|
return hash.digest("base64");
|
|
9771
11452
|
}
|
|
@@ -9850,7 +11531,7 @@ async function uploadBytes(options = {}, bytes, targetPath, upload = {}) {
|
|
|
9850
11531
|
if (!bytes.length) throw new Error("nothing to upload: the content is empty");
|
|
9851
11532
|
const target = drivePath(targetPath);
|
|
9852
11533
|
const contentType = upload.contentType ?? contentTypeFor(target);
|
|
9853
|
-
const sha2562 =
|
|
11534
|
+
const sha2562 = createHash10("sha256").update(bytes).digest("base64");
|
|
9854
11535
|
const granted = await requestUpload(options, { path: target, contentLength: bytes.length, contentType, sha256: sha2562, ...upload.overwrite ? { overwrite: true } : {} });
|
|
9855
11536
|
try {
|
|
9856
11537
|
await putPresigned(granted.uploadUrl, new Uint8Array(bytes), { contentType, contentLength: bytes.length, sha256: sha2562 });
|
|
@@ -10103,10 +11784,10 @@ function swapValue(text2, needle, replacement) {
|
|
|
10103
11784
|
}
|
|
10104
11785
|
|
|
10105
11786
|
// src/hooks/standInDigits.ts
|
|
10106
|
-
import { createHash as
|
|
11787
|
+
import { createHash as createHash11 } from "crypto";
|
|
10107
11788
|
function standInDigits(realDigits, identityName) {
|
|
10108
11789
|
if (!realDigits) return "";
|
|
10109
|
-
const digest =
|
|
11790
|
+
const digest = createHash11("sha256").update(`${identityName}:${realDigits}`).digest("hex");
|
|
10110
11791
|
let digits = "";
|
|
10111
11792
|
for (let i = 0; i < realDigits.length; i++)
|
|
10112
11793
|
digits += String(parseInt(digest[i % digest.length], 16) % 10);
|
|
@@ -10140,7 +11821,7 @@ var DeclaredStandIn = class _DeclaredStandIn {
|
|
|
10140
11821
|
};
|
|
10141
11822
|
|
|
10142
11823
|
// src/hooks/alias.ts
|
|
10143
|
-
import { createHash as
|
|
11824
|
+
import { createHash as createHash12, createHmac, randomBytes as randomBytes2 } from "crypto";
|
|
10144
11825
|
var GIVEN = [
|
|
10145
11826
|
"John",
|
|
10146
11827
|
"Mary",
|
|
@@ -10412,7 +12093,7 @@ function nameParts(name) {
|
|
|
10412
12093
|
function format(template, parts2) {
|
|
10413
12094
|
return template.replace(/\{(\w+)\}/g, (_, key2) => parts2[key2] ?? "").trim();
|
|
10414
12095
|
}
|
|
10415
|
-
var
|
|
12096
|
+
var pair2 = (real, fake, template) => [
|
|
10416
12097
|
format(template, real),
|
|
10417
12098
|
format(template, fake)
|
|
10418
12099
|
];
|
|
@@ -10472,7 +12153,7 @@ function namePairs(real, fake) {
|
|
|
10472
12153
|
const out = [[real, fake]];
|
|
10473
12154
|
if (realParts.given && realParts.surname) {
|
|
10474
12155
|
for (const template of NAME_FORMS) {
|
|
10475
|
-
const p =
|
|
12156
|
+
const p = pair2(realParts, fakeParts, template);
|
|
10476
12157
|
if (p[0].length > 2 && !p[0].includes("{")) out.push(p);
|
|
10477
12158
|
}
|
|
10478
12159
|
}
|
|
@@ -10510,7 +12191,7 @@ function emailPairs(real, fake) {
|
|
|
10510
12191
|
};
|
|
10511
12192
|
const out = [[real, fake]];
|
|
10512
12193
|
for (const template of EMAIL_FORMS) {
|
|
10513
|
-
const p =
|
|
12194
|
+
const p = pair2(realParts, fakeParts, template);
|
|
10514
12195
|
if (p[0].length > 2) out.push(p);
|
|
10515
12196
|
}
|
|
10516
12197
|
return dedupe(out);
|
|
@@ -10961,9 +12642,9 @@ var AliasMap = class _AliasMap {
|
|
|
10961
12642
|
});
|
|
10962
12643
|
if (alias.role === "private") {
|
|
10963
12644
|
for (const slug of this.slugs) {
|
|
10964
|
-
const standIn = "sha256:" +
|
|
12645
|
+
const standIn = "sha256:" + createHash12("sha256").update(`${slug}:${canonical(alias.kind, alias.display)}`, "utf8").digest("hex");
|
|
10965
12646
|
alias.variants.push([
|
|
10966
|
-
"sha256:" +
|
|
12647
|
+
"sha256:" + createHash12("sha256").update(`${slug}:${alias.canonical}`, "utf8").digest("hex"),
|
|
10967
12648
|
standIn
|
|
10968
12649
|
]);
|
|
10969
12650
|
this.aliasDigests.add(standIn.toLowerCase());
|
|
@@ -11778,7 +13459,7 @@ function inputSchema(shorthand, position) {
|
|
|
11778
13459
|
`${position}.input: expected a table of field = "type"`
|
|
11779
13460
|
);
|
|
11780
13461
|
const properties = {};
|
|
11781
|
-
const
|
|
13462
|
+
const required2 = [];
|
|
11782
13463
|
for (const [name, raw] of Object.entries(shorthand)) {
|
|
11783
13464
|
if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(name))
|
|
11784
13465
|
throw new HookConfigError(
|
|
@@ -11812,9 +13493,9 @@ function inputSchema(shorthand, position) {
|
|
|
11812
13493
|
`${position}.input.${name}: expected "type" or a schema table`
|
|
11813
13494
|
);
|
|
11814
13495
|
properties[name] = schema;
|
|
11815
|
-
if (!optional)
|
|
13496
|
+
if (!optional) required2.push(name);
|
|
11816
13497
|
}
|
|
11817
|
-
return { type: "object", properties, required };
|
|
13498
|
+
return { type: "object", properties, required: required2 };
|
|
11818
13499
|
}
|
|
11819
13500
|
function placeholders(value) {
|
|
11820
13501
|
if (typeof value === "string")
|
|
@@ -14638,11 +16319,20 @@ init_identity();
|
|
|
14638
16319
|
var tracing_exports = {};
|
|
14639
16320
|
__export(tracing_exports, {
|
|
14640
16321
|
IdentitySpanProcessor: () => IdentitySpanProcessor,
|
|
16322
|
+
MAX_MEDIA_BYTES: () => MAX_MEDIA_BYTES,
|
|
16323
|
+
MediaReference: () => MediaReference,
|
|
16324
|
+
MediaUploadError: () => MediaUploadError,
|
|
16325
|
+
MediaUploader: () => MediaUploader,
|
|
16326
|
+
SECRET_KEYS: () => SECRET_KEYS,
|
|
14641
16327
|
SESSION_ID_ATTRIBUTE: () => SESSION_ID_ATTRIBUTE,
|
|
16328
|
+
SecretRedactingSpanProcessor: () => SecretRedactingSpanProcessor,
|
|
14642
16329
|
SessionSpanProcessor: () => SessionSpanProcessor,
|
|
16330
|
+
SpanSecrets: () => SpanSecrets,
|
|
14643
16331
|
USER_ID_ATTRIBUTE: () => USER_ID_ATTRIBUTE,
|
|
16332
|
+
WORLD_SESSION_ID_ATTRIBUTE: () => WORLD_SESSION_ID_ATTRIBUTE,
|
|
14644
16333
|
flush: () => flush,
|
|
14645
16334
|
getAmbientSessionId: () => getAmbientSessionId,
|
|
16335
|
+
getCurrentWorldSessionId: () => getCurrentWorldSessionId,
|
|
14646
16336
|
identify: () => identify,
|
|
14647
16337
|
init: () => init2,
|
|
14648
16338
|
initIsolated: () => initIsolated,
|
|
@@ -14655,11 +16345,13 @@ __export(tracing_exports, {
|
|
|
14655
16345
|
resetAmbientUser: () => resetAmbientUser,
|
|
14656
16346
|
resolveUserId: () => resolveUserId,
|
|
14657
16347
|
shutdown: () => shutdown2,
|
|
14658
|
-
withSession: () => withSession
|
|
16348
|
+
withSession: () => withSession,
|
|
16349
|
+
withWorldSession: () => withWorldSession
|
|
14659
16350
|
});
|
|
14660
16351
|
init_init();
|
|
14661
16352
|
init_identity();
|
|
14662
|
-
|
|
16353
|
+
init_session();
|
|
16354
|
+
init_secrets();
|
|
14663
16355
|
|
|
14664
16356
|
// src/tracing/observe.ts
|
|
14665
16357
|
import { trace as trace3, context as context2, SpanStatusCode } from "@opentelemetry/api";
|
|
@@ -14922,6 +16614,9 @@ async function* observeClaude(stream, options) {
|
|
|
14922
16614
|
}
|
|
14923
16615
|
}
|
|
14924
16616
|
|
|
16617
|
+
// src/tracing/index.ts
|
|
16618
|
+
init_media();
|
|
16619
|
+
|
|
14925
16620
|
// src/index.ts
|
|
14926
16621
|
var tracing = {
|
|
14927
16622
|
...tracing_exports,
|
|
@@ -14940,8 +16635,12 @@ var tracing = {
|
|
|
14940
16635
|
}
|
|
14941
16636
|
};
|
|
14942
16637
|
export {
|
|
16638
|
+
ACTION_NAMES,
|
|
14943
16639
|
AGENT_ID_KEY,
|
|
14944
|
-
|
|
16640
|
+
ActionTracer,
|
|
16641
|
+
AnthropicComputer,
|
|
16642
|
+
AnthropicComputer20251124,
|
|
16643
|
+
ApiError,
|
|
14945
16644
|
BROWSER_GONE_PATTERNS,
|
|
14946
16645
|
BROWSER_TIERS,
|
|
14947
16646
|
BrowserActionRecorder,
|
|
@@ -14952,12 +16651,14 @@ export {
|
|
|
14952
16651
|
CALL_BODY_LIMIT_LABEL,
|
|
14953
16652
|
COMPUTER_USE_SPECS,
|
|
14954
16653
|
CheckoutProvenance,
|
|
16654
|
+
ComputerAction,
|
|
14955
16655
|
DEFAULT_BRANCH,
|
|
14956
16656
|
DEFAULT_TIMEOUT_SECONDS,
|
|
14957
16657
|
DEFAULT_VIEWPORT,
|
|
14958
16658
|
DRY_RUN_AGENT,
|
|
14959
16659
|
DRY_RUN_KIND,
|
|
14960
16660
|
DetachedPushError,
|
|
16661
|
+
Display,
|
|
14961
16662
|
DriftError,
|
|
14962
16663
|
DryRunOutcome,
|
|
14963
16664
|
ENV_GATEWAY_HOST,
|
|
@@ -14985,10 +16686,20 @@ export {
|
|
|
14985
16686
|
GatewayToolBlockedError,
|
|
14986
16687
|
HostedDryRunClient,
|
|
14987
16688
|
IDLE_WARNING_MINUTES,
|
|
16689
|
+
KEY_NAMES,
|
|
16690
|
+
KeyChord,
|
|
16691
|
+
NOT_EXECUTED,
|
|
14988
16692
|
NO_GRADER_REASON,
|
|
16693
|
+
NativeComputer,
|
|
16694
|
+
OpenAIComputer,
|
|
16695
|
+
OpenAIPreviewComputer,
|
|
16696
|
+
PLATFORM_TIMEOUT_DEFAULT_MS,
|
|
16697
|
+
PLATFORM_TIMEOUT_ENV,
|
|
16698
|
+
PendingSafetyChecks,
|
|
14989
16699
|
Persona,
|
|
14990
16700
|
PersonaError,
|
|
14991
16701
|
PersonasClient,
|
|
16702
|
+
PlatformTransport,
|
|
14992
16703
|
PushSlugConflict,
|
|
14993
16704
|
RECOVER_BUDGET_MS,
|
|
14994
16705
|
REPLAY_ENVIRONMENT,
|
|
@@ -14998,7 +16709,10 @@ export {
|
|
|
14998
16709
|
ReplayReport,
|
|
14999
16710
|
ReplaySuite,
|
|
15000
16711
|
ReplayTask,
|
|
16712
|
+
SANDBOX_REQUEST_TIMEOUT_MS,
|
|
16713
|
+
SECRET_KEY,
|
|
15001
16714
|
SESSION_STATES,
|
|
16715
|
+
SPAN_PREFIX,
|
|
15002
16716
|
STATUS_WAIT_CAP_SECONDS,
|
|
15003
16717
|
STRIP_PREFIX,
|
|
15004
16718
|
SUCCESS_METRIC_NAME_KEY,
|
|
@@ -15006,16 +16720,20 @@ export {
|
|
|
15006
16720
|
SURFACE_KINDS,
|
|
15007
16721
|
ScoreError,
|
|
15008
16722
|
ScoresClient,
|
|
16723
|
+
Screen,
|
|
15009
16724
|
SecretScrubber,
|
|
15010
16725
|
SessionLoadError,
|
|
15011
16726
|
SessionRecording,
|
|
15012
16727
|
SessionTrace,
|
|
15013
16728
|
StubMissError,
|
|
15014
16729
|
TRANSFORMS,
|
|
16730
|
+
TaskEditClient,
|
|
15015
16731
|
TaskRun,
|
|
15016
16732
|
TaskSessions,
|
|
15017
16733
|
ToolStubRegistry,
|
|
15018
16734
|
TraceDiff,
|
|
16735
|
+
TransportCause,
|
|
16736
|
+
UnreachableError,
|
|
15019
16737
|
UserProfileError,
|
|
15020
16738
|
UsersClient,
|
|
15021
16739
|
VERIFIER_REWARD_PREFIX,
|
|
@@ -15110,6 +16828,8 @@ export {
|
|
|
15110
16828
|
parseTransform,
|
|
15111
16829
|
parseWorldTaskRefs,
|
|
15112
16830
|
personas,
|
|
16831
|
+
platformTimeoutMs,
|
|
16832
|
+
playwrightKey,
|
|
15113
16833
|
preserveForm,
|
|
15114
16834
|
propose,
|
|
15115
16835
|
pull,
|
|
@@ -15119,8 +16839,10 @@ export {
|
|
|
15119
16839
|
pyText,
|
|
15120
16840
|
queryRows,
|
|
15121
16841
|
queryRowsSearch,
|
|
16842
|
+
readField,
|
|
15122
16843
|
readLocalMeta,
|
|
15123
16844
|
readToolCallRecords,
|
|
16845
|
+
rebaseConflicts,
|
|
15124
16846
|
redactActionArgs,
|
|
15125
16847
|
redactionOf,
|
|
15126
16848
|
registerArtifact,
|
|
@@ -15160,6 +16882,7 @@ export {
|
|
|
15160
16882
|
tracing,
|
|
15161
16883
|
uiEntryUrl,
|
|
15162
16884
|
uiUrl,
|
|
16885
|
+
uncommittedPaths,
|
|
15163
16886
|
updateTask,
|
|
15164
16887
|
upsertRunConfig,
|
|
15165
16888
|
users,
|