@withgateway/sdk 0.2.9 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/dist/cli.js +2355 -486
  2. package/dist/cli.js.map +1 -1
  3. package/dist/cli.mjs +2335 -466
  4. package/dist/cli.mjs.map +1 -1
  5. package/dist/files/index.d.mts +1 -0
  6. package/dist/files/index.d.ts +1 -0
  7. package/dist/files/index.js +1324 -21
  8. package/dist/files/index.js.map +1 -1
  9. package/dist/files/index.mjs +1322 -13
  10. package/dist/files/index.mjs.map +1 -1
  11. package/dist/{index-Cz8Q6Keo.d.mts → index-D6oi1TWE.d.mts} +93 -34
  12. package/dist/{index-BO2SNSgy.d.ts → index-DAb-FCMg.d.ts} +93 -34
  13. package/dist/index.d.mts +4 -3
  14. package/dist/index.d.ts +4 -3
  15. package/dist/index.js +1758 -116
  16. package/dist/index.js.map +1 -1
  17. package/dist/index.mjs +1720 -97
  18. package/dist/index.mjs.map +1 -1
  19. package/dist/media-CbcAfQvd.d.mts +83 -0
  20. package/dist/media-CbcAfQvd.d.ts +83 -0
  21. package/dist/traces/index.d.mts +1 -0
  22. package/dist/traces/index.d.ts +1 -0
  23. package/dist/traces/index.js +1321 -18
  24. package/dist/traces/index.js.map +1 -1
  25. package/dist/traces/index.mjs +1319 -10
  26. package/dist/traces/index.mjs.map +1 -1
  27. package/dist/tracing/index.d.mts +2 -1
  28. package/dist/tracing/index.d.ts +2 -1
  29. package/dist/tracing/index.js +512 -11
  30. package/dist/tracing/index.js.map +1 -1
  31. package/dist/tracing/index.mjs +501 -10
  32. package/dist/tracing/index.mjs.map +1 -1
  33. package/dist/worlds/index.d.mts +583 -63
  34. package/dist/worlds/index.d.ts +583 -63
  35. package/dist/worlds/index.js +1703 -94
  36. package/dist/worlds/index.js.map +1 -1
  37. package/dist/worlds/index.mjs +1689 -80
  38. package/dist/worlds/index.mjs.map +1 -1
  39. package/package.json +1 -1
  40. package/runtime/gatewaysdk/environment/schema/api.py +38 -56
  41. package/runtime/gatewaysdk/environment/schema/grading.py +1 -5
  42. package/runtime/gatewaysdk/environment/schema/host.py +53 -90
  43. package/runtime/gatewaysdk/environment/schema/local.py +15 -7
  44. package/runtime/gatewaysdk/environment/schema/runtime.py +9 -9
  45. package/runtime/gatewaysdk/environment/schema/skills/worlds-getting-started/SKILL.md +7 -7
  46. package/runtime/gatewaysdk/environment/schema/skills/worlds-getting-started/references/cli-mcp-map.md +1 -0
  47. package/runtime/gatewaysdk/environment/schema/tasks.py +25 -1
  48. package/skills/worlds-getting-started/SKILL.md +7 -7
  49. package/skills/worlds-getting-started/references/cli-mcp-map.md +1 -0
@@ -320,7 +320,7 @@ function withoutUiToken(url) {
320
320
  const [beforeHash, hash] = splitHash(url);
321
321
  const q = beforeHash.indexOf("?");
322
322
  if (q < 0) return url;
323
- const kept = beforeHash.slice(q + 1).split("&").filter((pair) => pair !== "" && pair.split("=")[0] !== UI_TOKEN_QUERY);
323
+ const kept = beforeHash.slice(q + 1).split("&").filter((pair2) => pair2 !== "" && pair2.split("=")[0] !== UI_TOKEN_QUERY);
324
324
  return beforeHash.slice(0, q) + (kept.length ? `?${kept.join("&")}` : "") + hash;
325
325
  }
326
326
  function splitHash(url) {
@@ -455,7 +455,7 @@ var SURFACE_KINDS, BROWSER_TIERS, DEFAULT_VIEWPORT, SETTLE_TIMEOUT_MS, SETTLE_QU
455
455
  var init_browser = __esm({
456
456
  "src/worlds/browser.ts"() {
457
457
  "use strict";
458
- init_session();
458
+ init_session2();
459
459
  init_browserReconnect();
460
460
  SURFACE_KINDS = ["tools", "api", "ui", "browser"];
461
461
  BROWSER_TIERS = ["standard", "premium"];
@@ -601,6 +601,10 @@ var init_browser = __esm({
601
601
  get agentId() {
602
602
  return this.recorder?.agentId ?? null;
603
603
  }
604
+ /** `text` with this session's credentials (UI token, browser address) removed. */
605
+ scrub(text2) {
606
+ return this.scrubber.scrub(text2);
607
+ }
604
608
  watchNetwork(page) {
605
609
  page.on("request", () => {
606
610
  this.inflight += 1;
@@ -887,6 +891,1269 @@ var init_browser = __esm({
887
891
  }
888
892
  });
889
893
 
894
+ // src/worlds/nativeComputer/actions.ts
895
+ function toNumber(value) {
896
+ if (typeof value !== "number" || !Number.isFinite(value))
897
+ throw new Error(`not a number: ${JSON.stringify(value) ?? String(value)}`);
898
+ return value;
899
+ }
900
+ function toInt(value) {
901
+ return Math.trunc(toNumber(value));
902
+ }
903
+ var ACTION_NAMES, SECRET_TEXT, BOUNDS, ComputerAction;
904
+ var init_actions = __esm({
905
+ "src/worlds/nativeComputer/actions.ts"() {
906
+ "use strict";
907
+ ACTION_NAMES = [
908
+ "screenshot",
909
+ "zoom",
910
+ "click",
911
+ "move",
912
+ "mouse_down",
913
+ "mouse_up",
914
+ "drag",
915
+ "scroll",
916
+ "type",
917
+ "key",
918
+ "hold_key",
919
+ "wait",
920
+ "cursor_position",
921
+ "history"
922
+ ];
923
+ SECRET_TEXT = "[redacted]";
924
+ BOUNDS = {
925
+ seconds: [0, 300],
926
+ repeat: [1, 100],
927
+ count: [1, 3],
928
+ dx: [-1e4, 1e4],
929
+ dy: [-1e4, 1e4]
930
+ };
931
+ ComputerAction = class {
932
+ constructor(name, args = {}) {
933
+ this.name = name;
934
+ this.args = args;
935
+ if (!ACTION_NAMES.includes(name))
936
+ throw new Error(`unknown computer action: ${name}`);
937
+ for (const [key, [low, high]] of Object.entries(BOUNDS)) {
938
+ const value = args[key];
939
+ if (value !== void 0 && !(Number(value) >= low && Number(value) <= high))
940
+ throw new Error(
941
+ `${name} ${key} must be between ${low} and ${high}, got ${String(value)}`
942
+ );
943
+ }
944
+ }
945
+ name;
946
+ args;
947
+ /** Flat arguments for the browser timeline and the trace: lists become
948
+ * `"x,y"` strings, and typed text is withheld when it went into a
949
+ * credential field. */
950
+ recordArgs(secretText) {
951
+ const out = {};
952
+ for (const [key, value] of Object.entries(this.args))
953
+ out[key] = Array.isArray(value) ? value.flat().join(",") : value;
954
+ if (secretText && "text" in out) out.text = SECRET_TEXT;
955
+ return out;
956
+ }
957
+ };
958
+ }
959
+ });
960
+
961
+ // src/worlds/nativeComputer/display.ts
962
+ var FIT_STEP, Display;
963
+ var init_display = __esm({
964
+ "src/worlds/nativeComputer/display.ts"() {
965
+ "use strict";
966
+ FIT_STEP = 0.98;
967
+ Display = class _Display {
968
+ constructor(width, height, viewportWidth, viewportHeight) {
969
+ this.width = width;
970
+ this.height = height;
971
+ this.viewportWidth = viewportWidth;
972
+ this.viewportHeight = viewportHeight;
973
+ }
974
+ width;
975
+ height;
976
+ viewportWidth;
977
+ viewportHeight;
978
+ /** `size` when the caller names one; otherwise the largest downscale of the
979
+ * viewport (at most 1:1) that `fits` the provider's limits. */
980
+ static forViewport(viewport, size, fits = () => true) {
981
+ const { width, height } = viewport;
982
+ if (size) return _Display.sized(size[0], size[1], width, height);
983
+ let scale = 1;
984
+ while (!fits(Math.round(width * scale), Math.round(height * scale)))
985
+ scale *= FIT_STEP;
986
+ return new _Display(
987
+ Math.round(width * scale),
988
+ Math.round(height * scale),
989
+ width,
990
+ height
991
+ );
992
+ }
993
+ /** A caller's display keeps the viewport's shape: screenshots are scaled
994
+ * uniformly, so another aspect ratio would map clicks off the image. */
995
+ static sized(width, height, viewportWidth, viewportHeight) {
996
+ if (width <= 0 || height <= 0)
997
+ throw new Error(`display ${width}x${height} must be positive`);
998
+ const sameShape = width * viewportHeight / viewportWidth;
999
+ if (Math.abs(sameShape - height) > 1)
1000
+ throw new Error(
1001
+ `display ${width}x${height} must keep the viewport's aspect ratio (${viewportWidth}x${viewportHeight}); try ${width}x${Math.round(sameShape)}`
1002
+ );
1003
+ return new _Display(width, height, viewportWidth, viewportHeight);
1004
+ }
1005
+ get scaled() {
1006
+ return this.width !== this.viewportWidth || this.height !== this.viewportHeight;
1007
+ }
1008
+ get scale() {
1009
+ return Math.min(
1010
+ this.width / this.viewportWidth,
1011
+ this.height / this.viewportHeight
1012
+ );
1013
+ }
1014
+ toPage(x, y) {
1015
+ return [
1016
+ x * this.viewportWidth / this.width,
1017
+ y * this.viewportHeight / this.height
1018
+ ];
1019
+ }
1020
+ };
1021
+ }
1022
+ });
1023
+
1024
+ // src/worlds/nativeComputer/screen.ts
1025
+ function pngWidth(png) {
1026
+ if (png.length < 24 || !png.subarray(0, 8).equals(PNG_SIGNATURE)) return null;
1027
+ return png.readUInt32BE(16);
1028
+ }
1029
+ function isNativePage(page) {
1030
+ const candidate = page;
1031
+ const mouse = candidate?.mouse;
1032
+ return typeof candidate?.context === "function" && NATIVE_METHODS.every((m) => typeof mouse?.[m] === "function");
1033
+ }
1034
+ var FOCUSED_FIELD_JS, SECRET_FOCUS, DRAG_STEPS, PNG_SIGNATURE, NATIVE_METHODS, Screen;
1035
+ var init_screen = __esm({
1036
+ "src/worlds/nativeComputer/screen.ts"() {
1037
+ "use strict";
1038
+ init_browser();
1039
+ 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(' '); })()";
1040
+ SECRET_FOCUS = ["password", "frame", "opaque"];
1041
+ DRAG_STEPS = 5;
1042
+ PNG_SIGNATURE = Buffer.from([
1043
+ 137,
1044
+ 80,
1045
+ 78,
1046
+ 71,
1047
+ 13,
1048
+ 10,
1049
+ 26,
1050
+ 10
1051
+ ]);
1052
+ NATIVE_METHODS = ["move", "click", "down", "up", "wheel"];
1053
+ Screen = class {
1054
+ constructor(browser, display) {
1055
+ this.browser = browser;
1056
+ this.display = display;
1057
+ }
1058
+ browser;
1059
+ display;
1060
+ cursor = [0, 0];
1061
+ pixelRatio = 1;
1062
+ handlers = {
1063
+ screenshot: async () => ({ image: await this.screenshot() }),
1064
+ zoom: (a) => this.zoom(a),
1065
+ click: (a) => this.click(a),
1066
+ move: (a) => this.held(a.args.modifiers ?? [], () => this.moveTo(this.point(a))),
1067
+ mouse_down: async (a) => {
1068
+ await this.page.mouse.down({ button: a.args.button ?? "left" });
1069
+ return {};
1070
+ },
1071
+ mouse_up: async (a) => {
1072
+ await this.page.mouse.up({ button: a.args.button ?? "left" });
1073
+ return {};
1074
+ },
1075
+ drag: (a) => this.drag(a),
1076
+ scroll: (a) => this.scroll(a),
1077
+ type: async (a) => {
1078
+ await this.page.keyboard.type(a.args.text ?? "");
1079
+ return {};
1080
+ },
1081
+ key: (a) => this.key(a),
1082
+ hold_key: (a) => this.held(
1083
+ a.args.keys ?? [],
1084
+ () => this.page.waitForTimeout((a.args.seconds ?? 0) * 1e3)
1085
+ ),
1086
+ wait: async (a) => {
1087
+ await this.page.waitForTimeout((a.args.seconds ?? 0) * 1e3);
1088
+ return {};
1089
+ },
1090
+ cursor_position: async () => ({
1091
+ text: `X=${this.cursor[0]}, Y=${this.cursor[1]}`
1092
+ }),
1093
+ history: async (a) => {
1094
+ const navigate = {
1095
+ back: () => this.page.goBack(),
1096
+ forward: () => this.page.goForward()
1097
+ };
1098
+ await navigate[a.args.direction ?? "back"]();
1099
+ return {};
1100
+ }
1101
+ };
1102
+ /** The live page (a new object after a reconnect), as pixel-level Playwright. */
1103
+ get page() {
1104
+ const page = this.browser.page;
1105
+ if (!isNativePage(page))
1106
+ throw new Error(
1107
+ "native computer use needs a Playwright page (mouse.move/click/down/up/wheel, context())"
1108
+ );
1109
+ return page;
1110
+ }
1111
+ run(action) {
1112
+ return this.handlers[action.name](action);
1113
+ }
1114
+ /** A PNG of the viewport at the model's display size. */
1115
+ async screenshot() {
1116
+ if (!this.display.scaled) return this.page.screenshot({ type: "png" });
1117
+ const { viewportWidth: width, viewportHeight: height } = this.display;
1118
+ return this.capture({ x: 0, y: 0, width, height }, this.display.scale);
1119
+ }
1120
+ /** Whether keystrokes go to a credential field (a password input, or one
1121
+ * named like a token, key or PIN), looking through shadow roots and
1122
+ * same-origin frames. An unreadable page, a cross-origin frame or a focus
1123
+ * that is not a text field (a closed shadow root's host) counts as one. */
1124
+ async focusedFieldIsSecret() {
1125
+ let described;
1126
+ try {
1127
+ described = String(await this.page.evaluate(FOCUSED_FIELD_JS) ?? "");
1128
+ } catch {
1129
+ return true;
1130
+ }
1131
+ return SECRET_FOCUS.some((prefix) => described.startsWith(prefix)) || SECRET_KEY.test(described);
1132
+ }
1133
+ /** CDP renders a clip at the page's device pixel ratio as well as its
1134
+ * `scale` (a Retina host doubles it), so a capture of the wrong width
1135
+ * measures that ratio and is taken once more, corrected. */
1136
+ async capture(clip, scale) {
1137
+ const wanted = Math.round(clip.width * scale);
1138
+ const png = await this.cdpCapture(clip, scale / this.pixelRatio);
1139
+ const width = pngWidth(png);
1140
+ if (width === null || Math.abs(width - wanted) <= 1) return png;
1141
+ this.pixelRatio *= width / wanted;
1142
+ return this.cdpCapture(clip, scale / this.pixelRatio);
1143
+ }
1144
+ async cdpCapture(clip, scale) {
1145
+ const page = this.page;
1146
+ const session = await page.context().newCDPSession(page);
1147
+ try {
1148
+ const shot = await session.send("Page.captureScreenshot", {
1149
+ format: "png",
1150
+ clip: { ...clip, scale }
1151
+ });
1152
+ return Buffer.from(shot.data, "base64");
1153
+ } finally {
1154
+ await session.detach();
1155
+ }
1156
+ }
1157
+ point(action) {
1158
+ const { x, y } = action.args;
1159
+ return x === void 0 || y === void 0 ? this.cursor : [x, y];
1160
+ }
1161
+ async moveTo(point2, steps = 1) {
1162
+ const [x, y] = this.display.toPage(point2[0], point2[1]);
1163
+ await this.page.mouse.move(x, y, { steps });
1164
+ this.cursor = point2;
1165
+ }
1166
+ async held(modifiers, fn) {
1167
+ for (const key of modifiers) await this.page.keyboard.down(key);
1168
+ try {
1169
+ await fn();
1170
+ } finally {
1171
+ for (const key of [...modifiers].reverse())
1172
+ await this.page.keyboard.up(key);
1173
+ }
1174
+ return {};
1175
+ }
1176
+ async zoom(action) {
1177
+ const [x0, y0, x1, y1] = action.args.region ?? [0, 0, 0, 0];
1178
+ const [left, top] = this.display.toPage(x0, y0);
1179
+ const [right, bottom] = this.display.toPage(x1, y1);
1180
+ if (right <= left || bottom <= top)
1181
+ throw new Error("zoom region must have x1 > x0 and y1 > y0");
1182
+ const width = right - left;
1183
+ const height = bottom - top;
1184
+ const scale = Math.min(
1185
+ this.display.width / width,
1186
+ this.display.height / height
1187
+ );
1188
+ return {
1189
+ image: await this.capture({ x: left, y: top, width, height }, scale)
1190
+ };
1191
+ }
1192
+ async click(action) {
1193
+ const point2 = this.point(action);
1194
+ return this.held(action.args.modifiers ?? [], async () => {
1195
+ await this.moveTo(point2);
1196
+ const [x, y] = this.display.toPage(point2[0], point2[1]);
1197
+ await this.page.mouse.click(x, y, {
1198
+ button: action.args.button ?? "left",
1199
+ clickCount: action.args.count ?? 1
1200
+ });
1201
+ });
1202
+ }
1203
+ async drag(action) {
1204
+ const path12 = action.args.path ?? [];
1205
+ if (path12.length < 2) throw new Error("a drag needs at least two points");
1206
+ return this.held(action.args.modifiers ?? [], async () => {
1207
+ await this.moveTo(path12[0]);
1208
+ await this.page.mouse.down({ button: "left" });
1209
+ try {
1210
+ for (const point2 of path12.slice(1)) await this.moveTo(point2, DRAG_STEPS);
1211
+ } finally {
1212
+ await this.page.mouse.up({ button: "left" });
1213
+ }
1214
+ });
1215
+ }
1216
+ async scroll(action) {
1217
+ await this.moveTo(this.point(action));
1218
+ const scale = this.display.scale;
1219
+ return this.held(
1220
+ action.args.modifiers ?? [],
1221
+ () => this.page.mouse.wheel(
1222
+ (action.args.dx ?? 0) / scale,
1223
+ (action.args.dy ?? 0) / scale
1224
+ )
1225
+ );
1226
+ }
1227
+ async key(action) {
1228
+ const combo = (action.args.keys ?? []).join("+");
1229
+ for (let i = 0; i < (action.args.repeat ?? 1); i += 1)
1230
+ await this.page.keyboard.press(combo);
1231
+ return {};
1232
+ }
1233
+ };
1234
+ }
1235
+ });
1236
+
1237
+ // src/tracing/media.ts
1238
+ import { createHash } from "crypto";
1239
+ async function putBytes(url, data, headers) {
1240
+ const controller = new AbortController();
1241
+ const timer = setTimeout(() => controller.abort(), PUT_TIMEOUT_MS);
1242
+ try {
1243
+ const res = await fetch(url, {
1244
+ method: "PUT",
1245
+ body: new Uint8Array(data),
1246
+ headers,
1247
+ signal: controller.signal
1248
+ });
1249
+ return {
1250
+ status: res.status,
1251
+ error: res.ok ? null : (await res.text()).slice(0, MAX_UPLOAD_ERROR)
1252
+ };
1253
+ } catch (error) {
1254
+ return {
1255
+ status: NETWORK_FAILURE_STATUS,
1256
+ error: error instanceof Error ? error.name : "Error"
1257
+ };
1258
+ } finally {
1259
+ clearTimeout(timer);
1260
+ }
1261
+ }
1262
+ var MEDIA_PATH, MAX_MEDIA_BYTES, PUT_TIMEOUT_MS, MAX_UPLOAD_ERROR, NETWORK_FAILURE_STATUS, MediaUploadError, MediaReference, MediaUploader;
1263
+ var init_media = __esm({
1264
+ "src/tracing/media.ts"() {
1265
+ "use strict";
1266
+ init_transport();
1267
+ MEDIA_PATH = "/api/public/media";
1268
+ MAX_MEDIA_BYTES = 5 * 1024 * 1024;
1269
+ PUT_TIMEOUT_MS = 3e4;
1270
+ MAX_UPLOAD_ERROR = 500;
1271
+ NETWORK_FAILURE_STATUS = 599;
1272
+ MediaUploadError = class extends Error {
1273
+ constructor(message, status) {
1274
+ super(message);
1275
+ this.status = status;
1276
+ this.name = "MediaUploadError";
1277
+ }
1278
+ status;
1279
+ };
1280
+ MediaReference = class {
1281
+ constructor(mediaId, contentType) {
1282
+ this.mediaId = mediaId;
1283
+ this.contentType = contentType;
1284
+ }
1285
+ mediaId;
1286
+ contentType;
1287
+ toString() {
1288
+ return `@@@langfuseMedia:type=${this.contentType}|id=${this.mediaId}|source=bytes@@@`;
1289
+ }
1290
+ };
1291
+ MediaUploader = class _MediaUploader {
1292
+ constructor(transport, put = putBytes, maxBytes = MAX_MEDIA_BYTES) {
1293
+ this.transport = transport;
1294
+ this.put = put;
1295
+ this.maxBytes = maxBytes;
1296
+ }
1297
+ transport;
1298
+ put;
1299
+ maxBytes;
1300
+ /** The uploader for `GATEWAY_HOST` / `GATEWAY_PUBLIC_KEY` /
1301
+ * `GATEWAY_SECRET_KEY` (the keys tracing exports with); null when any is unset. */
1302
+ static fromEnv(env = process.env) {
1303
+ const host = env.GATEWAY_HOST;
1304
+ const publicKey = env.GATEWAY_PUBLIC_KEY;
1305
+ const secretKey = env.GATEWAY_SECRET_KEY;
1306
+ if (!host || !publicKey || !secretKey) return null;
1307
+ return new _MediaUploader(
1308
+ new PlatformTransport({
1309
+ host: host.replace(/\/$/, ""),
1310
+ publicKey,
1311
+ secretKey
1312
+ })
1313
+ );
1314
+ }
1315
+ /** Store `data` linked to the trace (and observation) and return its reference. */
1316
+ async upload(data, link) {
1317
+ if (data.length > this.maxBytes)
1318
+ throw new MediaUploadError(
1319
+ `media is ${data.length} bytes, over the ${this.maxBytes}-byte cap`
1320
+ );
1321
+ const sha256Hash = createHash("sha256").update(data).digest("base64");
1322
+ const answer = await this.send("POST", MEDIA_PATH, {
1323
+ traceId: link.traceId,
1324
+ observationId: link.observationId,
1325
+ contentType: link.contentType,
1326
+ contentLength: data.length,
1327
+ sha256Hash,
1328
+ field: link.field
1329
+ });
1330
+ if (typeof answer.mediaId !== "string" || !answer.mediaId)
1331
+ throw new MediaUploadError(
1332
+ "POST /api/public/media answered without a mediaId"
1333
+ );
1334
+ const reference = new MediaReference(answer.mediaId, link.contentType);
1335
+ if (answer.uploadUrl)
1336
+ await this.store(reference, answer.uploadUrl, data, sha256Hash);
1337
+ return reference;
1338
+ }
1339
+ async store(reference, url, data, sha256Hash) {
1340
+ const started = Date.now();
1341
+ const { status, error } = await this.put(url, data, {
1342
+ "Content-Type": reference.contentType,
1343
+ "x-amz-checksum-sha256": sha256Hash,
1344
+ "x-ms-blob-type": "BlockBlob"
1345
+ });
1346
+ await this.send(
1347
+ "PATCH",
1348
+ `${MEDIA_PATH}/${encodeURIComponent(reference.mediaId)}`,
1349
+ {
1350
+ uploadedAt: (/* @__PURE__ */ new Date()).toISOString(),
1351
+ uploadHttpStatus: status,
1352
+ uploadHttpError: error,
1353
+ uploadTimeMs: Date.now() - started
1354
+ }
1355
+ );
1356
+ if (status < 200 || status >= 300)
1357
+ throw new MediaUploadError(
1358
+ `media storage refused the upload (HTTP ${status})`,
1359
+ status
1360
+ );
1361
+ }
1362
+ async send(method, route, body) {
1363
+ const reply = await this.transport.send(method, route, body);
1364
+ if (!reply.ok)
1365
+ throw new MediaUploadError(
1366
+ `${method} ${route} -> ${reply.status}`,
1367
+ reply.status
1368
+ );
1369
+ return reply.text ? JSON.parse(reply.text) : {};
1370
+ }
1371
+ };
1372
+ }
1373
+ });
1374
+
1375
+ // src/worlds/nativeComputer/trace.ts
1376
+ function loadOtelApi() {
1377
+ if (otelApi !== void 0) return otelApi;
1378
+ try {
1379
+ otelApi = __require("@opentelemetry/api");
1380
+ } catch {
1381
+ otelApi = null;
1382
+ }
1383
+ return otelApi;
1384
+ }
1385
+ function errorText(error) {
1386
+ return error instanceof Error ? `${error.name}: ${error.message}` : String(error);
1387
+ }
1388
+ function errorName(error) {
1389
+ return error instanceof Error ? error.name : "Error";
1390
+ }
1391
+ var SPAN_PREFIX, MAX_UPLOAD_FAILURES, TRACER_NAME, MAX_ERROR, otelApi, ActionTracer;
1392
+ var init_trace = __esm({
1393
+ "src/worlds/nativeComputer/trace.ts"() {
1394
+ "use strict";
1395
+ init_media();
1396
+ SPAN_PREFIX = "computer.";
1397
+ MAX_UPLOAD_FAILURES = 3;
1398
+ TRACER_NAME = "@withgateway/sdk";
1399
+ MAX_ERROR = 1e3;
1400
+ ActionTracer = class _ActionTracer {
1401
+ constructor(media, warn2 = (m) => console.warn(m)) {
1402
+ this.media = media;
1403
+ this.warn = warn2;
1404
+ }
1405
+ media;
1406
+ warn;
1407
+ failures = 0;
1408
+ warned = false;
1409
+ static fromEnv() {
1410
+ return new _ActionTracer(MediaUploader.fromEnv());
1411
+ }
1412
+ /** `args` are already redacted. A failure's status goes through `scrub`:
1413
+ * browser errors quote the session's ws URL and UI token. */
1414
+ async span(action, args, run, capture, scrub) {
1415
+ const otel = loadOtelApi();
1416
+ if (!otel) return run();
1417
+ const { SpanStatusCode, trace: trace3 } = otel;
1418
+ const attributes = {
1419
+ "gateway.observation.type": "tool",
1420
+ "tool.name": SPAN_PREFIX + action.name,
1421
+ "gateway.observation.input": JSON.stringify({
1422
+ action: action.name,
1423
+ ...args
1424
+ })
1425
+ };
1426
+ return trace3.getTracer(TRACER_NAME).startActiveSpan(
1427
+ SPAN_PREFIX + action.name,
1428
+ { attributes },
1429
+ async (span) => {
1430
+ try {
1431
+ const result = await run();
1432
+ await this.finish(span, result, capture);
1433
+ span.setStatus({ code: SpanStatusCode.OK });
1434
+ return result;
1435
+ } catch (error) {
1436
+ span.setStatus({
1437
+ code: SpanStatusCode.ERROR,
1438
+ message: scrub(errorText(error)).slice(0, MAX_ERROR)
1439
+ });
1440
+ throw error;
1441
+ } finally {
1442
+ span.end();
1443
+ }
1444
+ }
1445
+ );
1446
+ }
1447
+ async finish(span, result, capture) {
1448
+ if (!span.isRecording()) return;
1449
+ const output = {
1450
+ screenshot: await this.screenshot(span, result, capture)
1451
+ };
1452
+ if (result.text !== void 0) output.text = result.text;
1453
+ span.setAttribute("gateway.observation.output", JSON.stringify(output));
1454
+ }
1455
+ async screenshot(span, result, capture) {
1456
+ let png;
1457
+ try {
1458
+ png = result.image ?? await capture();
1459
+ } catch (error) {
1460
+ return `[screenshot unavailable: ${errorName(error)}]`;
1461
+ }
1462
+ return this.reference(png, span);
1463
+ }
1464
+ async reference(png, span) {
1465
+ if (!this.media)
1466
+ return "[screenshot not uploaded: GATEWAY_HOST / GATEWAY_PUBLIC_KEY / GATEWAY_SECRET_KEY unset]";
1467
+ if (this.failures >= MAX_UPLOAD_FAILURES)
1468
+ return "[screenshot not uploaded: uploads disabled after repeated failures]";
1469
+ const { traceId, spanId } = span.spanContext();
1470
+ try {
1471
+ const reference = await this.media.upload(png, {
1472
+ contentType: "image/png",
1473
+ traceId,
1474
+ observationId: spanId,
1475
+ field: "output"
1476
+ });
1477
+ this.failures = 0;
1478
+ return reference.toString();
1479
+ } catch (error) {
1480
+ return this.failed(error);
1481
+ }
1482
+ }
1483
+ failed(error) {
1484
+ this.failures += 1;
1485
+ if (!this.warned) {
1486
+ this.warned = true;
1487
+ this.warn(
1488
+ `native computer: screenshot upload failed (${errorName(error)}: ${error instanceof Error ? error.message : String(error)}); spans keep going without it`
1489
+ );
1490
+ }
1491
+ return `[screenshot not uploaded: ${errorName(error)}]`;
1492
+ }
1493
+ };
1494
+ }
1495
+ });
1496
+
1497
+ // src/worlds/nativeComputer/base.ts
1498
+ function readField(item, ...names) {
1499
+ const record = item ?? {};
1500
+ return names.map((name) => record[name]).find((value) => value !== void 0 && value !== null);
1501
+ }
1502
+ var REPLAYABLE, SETTLING, EVENT_PREFIX, NativeComputer;
1503
+ var init_base = __esm({
1504
+ "src/worlds/nativeComputer/base.ts"() {
1505
+ "use strict";
1506
+ init_browser();
1507
+ init_actions();
1508
+ init_display();
1509
+ init_screen();
1510
+ init_trace();
1511
+ REPLAYABLE = /* @__PURE__ */ new Set(["screenshot", "zoom", "cursor_position", "wait"]);
1512
+ SETTLING = /* @__PURE__ */ new Set(["click", "mouse_up", "drag", "key", "history"]);
1513
+ EVENT_PREFIX = "computer_";
1514
+ NativeComputer = class _NativeComputer {
1515
+ constructor(browser, options = {}) {
1516
+ this.browser = browser;
1517
+ const kind = this.constructor;
1518
+ this.display = Display.forViewport(
1519
+ browser.viewport,
1520
+ options.display,
1521
+ (w, h) => kind.fits(w, h)
1522
+ );
1523
+ this.screen = new Screen(browser, this.display);
1524
+ this.tracer = options.tracer ?? ActionTracer.fromEnv();
1525
+ }
1526
+ browser;
1527
+ static kinds = /* @__PURE__ */ new Map();
1528
+ display;
1529
+ screen;
1530
+ tracer;
1531
+ queue = Promise.resolve();
1532
+ static register(provider, kind) {
1533
+ _NativeComputer.kinds.set(provider, kind);
1534
+ }
1535
+ static get providers() {
1536
+ return [..._NativeComputer.kinds.keys()].sort();
1537
+ }
1538
+ static forProvider(provider, browser, options = {}) {
1539
+ const Kind = _NativeComputer.kinds.get(provider);
1540
+ if (!Kind)
1541
+ throw new Error(
1542
+ `unknown computer-use provider '${provider}'; choose from ${_NativeComputer.providers.join(", ")}`
1543
+ );
1544
+ return new Kind(browser, options);
1545
+ }
1546
+ /** Whether a screenshot of this size is within the provider's limits. */
1547
+ static fits(_width, _height) {
1548
+ return true;
1549
+ }
1550
+ /** Run one provider-shaped action (an OpenAI action object, or an Anthropic
1551
+ * `{ action: "left_click", ... }` input) and return what it produced: the
1552
+ * door for any agent framework that hands actions over one at a time. */
1553
+ executeAction(raw) {
1554
+ return this.perform(this.parse(raw));
1555
+ }
1556
+ /** Run one action on the page: reported on the session's browser timeline
1557
+ * and, when tracing is on, as a span with the screen after. */
1558
+ async perform(action) {
1559
+ const secret = action.name === "type" && await this.screen.focusedFieldIsSecret();
1560
+ const event = EVENT_PREFIX + action.name;
1561
+ const args = redactActionArgs(event, action.recordArgs(secret));
1562
+ return this.tracer.span(
1563
+ action,
1564
+ args,
1565
+ () => this.browser.act(
1566
+ event,
1567
+ args,
1568
+ () => this.runOnScreen(action),
1569
+ this.onLoss(action)
1570
+ ),
1571
+ () => this.screen.screenshot(),
1572
+ (text2) => this.browser.scrub(text2)
1573
+ );
1574
+ }
1575
+ async performAll(actions) {
1576
+ const results = [];
1577
+ for (const action of actions) results.push(await this.perform(action));
1578
+ return results;
1579
+ }
1580
+ /** The screen as the model sees it, as a traced `screenshot` action. */
1581
+ async screenshot() {
1582
+ return (await this.perform(new ComputerAction("screenshot"))).image ?? Buffer.alloc(0);
1583
+ }
1584
+ /** Run `fn` after every earlier call made through here: the AI SDK starts a
1585
+ * step's tool calls concurrently, but one screen takes one action at a time. */
1586
+ serial(fn) {
1587
+ const next = this.queue.then(fn, fn);
1588
+ this.queue = next.catch(() => void 0);
1589
+ return next;
1590
+ }
1591
+ async runOnScreen(action) {
1592
+ const result = await this.screen.run(action);
1593
+ if (SETTLING.has(action.name)) await this.browser.settle();
1594
+ return result;
1595
+ }
1596
+ onLoss(action) {
1597
+ return REPLAYABLE.has(action.name) ? "retry" : "report";
1598
+ }
1599
+ };
1600
+ }
1601
+ });
1602
+
1603
+ // src/worlds/nativeComputer/keys.ts
1604
+ function playwrightKey(token) {
1605
+ return KEY_NAMES[token.toLowerCase()] ?? token;
1606
+ }
1607
+ function letterOrName(key) {
1608
+ return /^[a-zA-Z]$/.test(key) ? key.toLowerCase() : playwrightKey(key);
1609
+ }
1610
+ function modifierChord(text2) {
1611
+ return typeof text2 === "string" && text2 ? [...KeyChord.fromXdotool(text2).keys] : [];
1612
+ }
1613
+ function modifierKeys(keys) {
1614
+ return Array.isArray(keys) && keys.length > 0 ? [...KeyChord.fromKeys(keys.map(String)).keys] : [];
1615
+ }
1616
+ var F_KEYS, KEY_NAMES, KeyChord;
1617
+ var init_keys = __esm({
1618
+ "src/worlds/nativeComputer/keys.ts"() {
1619
+ "use strict";
1620
+ F_KEYS = Object.fromEntries(
1621
+ Array.from({ length: 12 }, (_, i) => [`f${i + 1}`, `F${i + 1}`])
1622
+ );
1623
+ KEY_NAMES = {
1624
+ return: "Enter",
1625
+ enter: "Enter",
1626
+ kp_enter: "Enter",
1627
+ esc: "Escape",
1628
+ escape: "Escape",
1629
+ tab: "Tab",
1630
+ space: "Space",
1631
+ backspace: "Backspace",
1632
+ delete: "Delete",
1633
+ del: "Delete",
1634
+ insert: "Insert",
1635
+ home: "Home",
1636
+ end: "End",
1637
+ pageup: "PageUp",
1638
+ page_up: "PageUp",
1639
+ prior: "PageUp",
1640
+ pagedown: "PageDown",
1641
+ page_down: "PageDown",
1642
+ next: "PageDown",
1643
+ up: "ArrowUp",
1644
+ arrowup: "ArrowUp",
1645
+ down: "ArrowDown",
1646
+ arrowdown: "ArrowDown",
1647
+ left: "ArrowLeft",
1648
+ arrowleft: "ArrowLeft",
1649
+ right: "ArrowRight",
1650
+ arrowright: "ArrowRight",
1651
+ ctrl: "Control",
1652
+ control: "Control",
1653
+ shift: "Shift",
1654
+ alt: "Alt",
1655
+ option: "Alt",
1656
+ super: "Meta",
1657
+ meta: "Meta",
1658
+ cmd: "Meta",
1659
+ command: "Meta",
1660
+ win: "Meta",
1661
+ capslock: "CapsLock",
1662
+ caps_lock: "CapsLock",
1663
+ plus: "+",
1664
+ minus: "-",
1665
+ ...F_KEYS
1666
+ };
1667
+ KeyChord = class _KeyChord {
1668
+ constructor(keys) {
1669
+ this.keys = keys;
1670
+ if (keys.length === 0)
1671
+ throw new Error("a key action needs at least one key");
1672
+ }
1673
+ keys;
1674
+ /** `ctrl+shift+t` / `Return`: Anthropic's vocabulary, case kept. */
1675
+ static fromXdotool(text2) {
1676
+ return new _KeyChord(
1677
+ text2.trim().split("+").filter(Boolean).map(playwrightKey)
1678
+ );
1679
+ }
1680
+ /** `["CTRL", "A"]`: OpenAI's vocabulary. A lone letter is the unshifted key. */
1681
+ static fromKeys(keys) {
1682
+ return new _KeyChord(keys.map(letterOrName));
1683
+ }
1684
+ /** What `page.keyboard.press` takes: `Control+a`. */
1685
+ get combo() {
1686
+ return this.keys.join("+");
1687
+ }
1688
+ };
1689
+ }
1690
+ });
1691
+
1692
+ // src/worlds/nativeComputer/anthropic.ts
1693
+ function required(raw, key) {
1694
+ const value = raw[key];
1695
+ if (value === void 0 || value === null)
1696
+ throw new Error(`${String(raw.action)} needs ${key}`);
1697
+ return value;
1698
+ }
1699
+ function pair(raw, key) {
1700
+ const value = required(raw, key);
1701
+ return [toInt(value[0]), toInt(value[1])];
1702
+ }
1703
+ function point(raw) {
1704
+ if (raw.coordinate === void 0 || raw.coordinate === null) return {};
1705
+ const [x, y] = pair(raw, "coordinate");
1706
+ return { x, y };
1707
+ }
1708
+ function chord(raw) {
1709
+ return [...KeyChord.fromXdotool(String(required(raw, "text"))).keys];
1710
+ }
1711
+ function click(button, count) {
1712
+ return (raw) => new ComputerAction("click", {
1713
+ ...point(raw),
1714
+ button,
1715
+ count,
1716
+ modifiers: modifierChord(raw.text)
1717
+ });
1718
+ }
1719
+ var SCROLL_STEP_PX, NOT_EXECUTED, MAX_ERROR2, SCROLL_DIRECTIONS, MEMBERS, AnthropicComputer, AnthropicComputer20251124;
1720
+ var init_anthropic = __esm({
1721
+ "src/worlds/nativeComputer/anthropic.ts"() {
1722
+ "use strict";
1723
+ init_actions();
1724
+ init_base();
1725
+ init_keys();
1726
+ SCROLL_STEP_PX = 100;
1727
+ NOT_EXECUTED = "Not executed: an earlier computer action in this turn failed.";
1728
+ MAX_ERROR2 = 1e3;
1729
+ SCROLL_DIRECTIONS = {
1730
+ up: [0, -1],
1731
+ down: [0, 1],
1732
+ left: [-1, 0],
1733
+ right: [1, 0]
1734
+ };
1735
+ MEMBERS = {
1736
+ screenshot: () => new ComputerAction("screenshot"),
1737
+ zoom: (raw) => new ComputerAction("zoom", {
1738
+ region: required(raw, "region").map(toInt)
1739
+ }),
1740
+ left_click: click("left", 1),
1741
+ right_click: click("right", 1),
1742
+ middle_click: click("middle", 1),
1743
+ double_click: click("left", 2),
1744
+ triple_click: click("left", 3),
1745
+ left_click_drag: (raw) => new ComputerAction("drag", {
1746
+ path: [pair(raw, "start_coordinate"), pair(raw, "coordinate")],
1747
+ modifiers: modifierChord(raw.text)
1748
+ }),
1749
+ mouse_move: (raw) => {
1750
+ const [x, y] = pair(raw, "coordinate");
1751
+ return new ComputerAction("move", { x, y });
1752
+ },
1753
+ left_mouse_down: () => new ComputerAction("mouse_down", { button: "left" }),
1754
+ left_mouse_up: () => new ComputerAction("mouse_up", { button: "left" }),
1755
+ cursor_position: () => new ComputerAction("cursor_position"),
1756
+ scroll: (raw) => {
1757
+ const direction = String(raw.scroll_direction ?? "down");
1758
+ if (!Object.hasOwn(SCROLL_DIRECTIONS, direction))
1759
+ throw new Error(
1760
+ `scroll_direction must be one of ${Object.keys(SCROLL_DIRECTIONS).join(", ")}`
1761
+ );
1762
+ const [dx, dy] = SCROLL_DIRECTIONS[direction];
1763
+ const amount = toInt(raw.scroll_amount ?? 1) * SCROLL_STEP_PX;
1764
+ return new ComputerAction("scroll", {
1765
+ ...point(raw),
1766
+ dx: dx * amount,
1767
+ dy: dy * amount,
1768
+ modifiers: modifierChord(raw.text)
1769
+ });
1770
+ },
1771
+ type: (raw) => new ComputerAction("type", { text: String(required(raw, "text")) }),
1772
+ key: (raw) => new ComputerAction("key", {
1773
+ keys: chord(raw),
1774
+ repeat: toInt(raw.repeat ?? 1)
1775
+ }),
1776
+ hold_key: (raw) => new ComputerAction("hold_key", {
1777
+ keys: chord(raw),
1778
+ seconds: toNumber(required(raw, "duration"))
1779
+ }),
1780
+ wait: (raw) => new ComputerAction("wait", { seconds: toNumber(raw.duration ?? 1) })
1781
+ };
1782
+ AnthropicComputer = class _AnthropicComputer extends NativeComputer {
1783
+ static TOOL_TYPE = "computer_toolset_20260801";
1784
+ static TOOLSET = "computer";
1785
+ static BETA = null;
1786
+ static MAX_LONG_EDGE = 2576;
1787
+ static MAX_VISUAL_TOKENS = 4784;
1788
+ static PATCH_PX = 28;
1789
+ static fits(width, height) {
1790
+ const tokens = Math.ceil(width / this.PATCH_PX) * Math.ceil(height / this.PATCH_PX);
1791
+ return Math.max(width, height) <= this.MAX_LONG_EDGE && tokens <= this.MAX_VISUAL_TOKENS;
1792
+ }
1793
+ tool() {
1794
+ return { type: _AnthropicComputer.TOOL_TYPE };
1795
+ }
1796
+ /** Whether a content block is a call to this computer. */
1797
+ owns(block) {
1798
+ return readField(block, "type") === "tool_use" && readField(block, "toolset_name") === _AnthropicComputer.TOOLSET;
1799
+ }
1800
+ member(block) {
1801
+ return [
1802
+ String(readField(block, "name")),
1803
+ { ...readField(block, "input") ?? {} }
1804
+ ];
1805
+ }
1806
+ parse(raw) {
1807
+ const name = String(readField(raw, "action"));
1808
+ const parser = Object.hasOwn(MEMBERS, name) ? MEMBERS[name] : void 0;
1809
+ if (!parser) throw new Error(`unknown computer action: ${name}`);
1810
+ return parser(raw);
1811
+ }
1812
+ /** Run every computer `tool_use` in a response's content, in order, and
1813
+ * return one `tool_result` per block. Other blocks are skipped. */
1814
+ async execute(content) {
1815
+ const results = [];
1816
+ let failed = false;
1817
+ for (const block of content) {
1818
+ if (!this.owns(block)) continue;
1819
+ if (failed) {
1820
+ results.push(this.envelope(block, NOT_EXECUTED, true));
1821
+ continue;
1822
+ }
1823
+ const [result, blockFailed] = await this.runBlock(block);
1824
+ results.push(result);
1825
+ failed = blockFailed;
1826
+ }
1827
+ return results;
1828
+ }
1829
+ /** The content an `ActionResult` goes back to the model as. */
1830
+ static content(result) {
1831
+ if (result.image)
1832
+ return [
1833
+ {
1834
+ type: "image",
1835
+ source: {
1836
+ type: "base64",
1837
+ media_type: "image/png",
1838
+ data: result.image.toString("base64")
1839
+ }
1840
+ }
1841
+ ];
1842
+ return [{ type: "text", text: result.text ?? "OK" }];
1843
+ }
1844
+ /** For `anthropic.tools.computerToolset_20260801({ ...computer.aiSdk() })`
1845
+ * (or `computer_20251124` with the legacy kind): `execute` runs one action
1846
+ * and returns `{ type: "image", data }` or text; `toModelOutput` turns that
1847
+ * into the tool result. Calls run one at a time, and once a call fails the
1848
+ * rest of that step's calls answer as not executed. */
1849
+ aiSdk() {
1850
+ let failedStep;
1851
+ const execute = (input, options) => this.serial(async () => {
1852
+ const step = options?.messages?.length;
1853
+ if (step !== void 0 && step === failedStep)
1854
+ throw new Error(NOT_EXECUTED);
1855
+ try {
1856
+ return _AnthropicComputer.aiSdkOutput(await this.executeAction(input));
1857
+ } catch (error) {
1858
+ failedStep = step;
1859
+ throw error instanceof Error ? new Error(this.browser.scrub(error.message)) : error;
1860
+ }
1861
+ });
1862
+ return {
1863
+ execute,
1864
+ toModelOutput: ({ output }) => _AnthropicComputer.aiSdkModelOutput(output)
1865
+ };
1866
+ }
1867
+ static aiSdkOutput(result) {
1868
+ if (result.image)
1869
+ return { type: "image", data: result.image.toString("base64") };
1870
+ return result.text ?? "OK";
1871
+ }
1872
+ /** `image-data` is what AI SDK 6's Anthropic provider turns into an image
1873
+ * block; AI SDK 7 still accepts it (and converts it to a `file` part). */
1874
+ static aiSdkModelOutput(output) {
1875
+ if (typeof output === "string") return { type: "text", value: output };
1876
+ return {
1877
+ type: "content",
1878
+ value: [
1879
+ { type: "image-data", data: output.data, mediaType: "image/png" }
1880
+ ]
1881
+ };
1882
+ }
1883
+ envelope(block, content, isError = false) {
1884
+ return {
1885
+ type: "tool_result",
1886
+ tool_use_id: String(readField(block, "id")),
1887
+ toolset_name: _AnthropicComputer.TOOLSET,
1888
+ content,
1889
+ ...isError ? { is_error: true } : {}
1890
+ };
1891
+ }
1892
+ async runBlock(block) {
1893
+ const [name, payload] = this.member(block);
1894
+ try {
1895
+ const result = await this.executeAction({ ...payload, action: name });
1896
+ return [this.envelope(block, _AnthropicComputer.content(result)), false];
1897
+ } catch (error) {
1898
+ const detail = error instanceof Error ? `${error.name}: ${error.message}` : String(error);
1899
+ return [
1900
+ this.envelope(
1901
+ block,
1902
+ this.browser.scrub(`Error: ${detail}`).slice(0, MAX_ERROR2),
1903
+ true
1904
+ ),
1905
+ true
1906
+ ];
1907
+ }
1908
+ }
1909
+ };
1910
+ AnthropicComputer20251124 = class _AnthropicComputer20251124 extends AnthropicComputer {
1911
+ static TOOL_TYPE = "computer_20251124";
1912
+ static BETA = "computer-use-2025-11-24";
1913
+ static MAX_LONG_EDGE = 1568;
1914
+ static MAX_PIXELS = 115e4;
1915
+ static fits(width, height) {
1916
+ return Math.max(width, height) <= this.MAX_LONG_EDGE && width * height <= this.MAX_PIXELS;
1917
+ }
1918
+ tool() {
1919
+ return {
1920
+ type: _AnthropicComputer20251124.TOOL_TYPE,
1921
+ name: AnthropicComputer.TOOLSET,
1922
+ display_width_px: this.display.width,
1923
+ display_height_px: this.display.height,
1924
+ enable_zoom: true
1925
+ };
1926
+ }
1927
+ owns(block) {
1928
+ return readField(block, "type") === "tool_use" && readField(block, "name") === AnthropicComputer.TOOLSET;
1929
+ }
1930
+ member(block) {
1931
+ const { action, ...payload } = readField(block, "input") ?? {};
1932
+ return [String(action ?? ""), payload];
1933
+ }
1934
+ envelope(block, content, isError = false) {
1935
+ const { toolset_name: _dropped, ...rest } = super.envelope(
1936
+ block,
1937
+ content,
1938
+ isError
1939
+ );
1940
+ return rest;
1941
+ }
1942
+ };
1943
+ NativeComputer.register("anthropic", AnthropicComputer);
1944
+ NativeComputer.register(
1945
+ "anthropic-computer-20251124",
1946
+ AnthropicComputer20251124
1947
+ );
1948
+ }
1949
+ });
1950
+
1951
+ // src/worlds/nativeComputer/openai.ts
1952
+ function safetyCheck(raw) {
1953
+ const check = { id: String(readField(raw, "id") ?? "") };
1954
+ const code = readField(raw, "code");
1955
+ const message = readField(raw, "message");
1956
+ if (code !== void 0) check.code = String(code);
1957
+ if (message !== void 0) check.message = String(message);
1958
+ return check;
1959
+ }
1960
+ function dataUrl(png) {
1961
+ return `data:image/png;base64,${png.toString("base64")}`;
1962
+ }
1963
+ function xy(raw) {
1964
+ return {
1965
+ x: toInt(readField(raw, "x") ?? 0),
1966
+ y: toInt(readField(raw, "y") ?? 0)
1967
+ };
1968
+ }
1969
+ function held(raw) {
1970
+ return modifierKeys(readField(raw, "keys"));
1971
+ }
1972
+ var WAIT_SECONDS, BUTTONS, HISTORY_BUTTONS, PendingSafetyChecks, ACTIONS, OpenAIComputer, OpenAIPreviewComputer;
1973
+ var init_openai = __esm({
1974
+ "src/worlds/nativeComputer/openai.ts"() {
1975
+ "use strict";
1976
+ init_actions();
1977
+ init_base();
1978
+ init_keys();
1979
+ WAIT_SECONDS = 1;
1980
+ BUTTONS = {
1981
+ left: "left",
1982
+ right: "right",
1983
+ wheel: "middle",
1984
+ middle: "middle"
1985
+ };
1986
+ HISTORY_BUTTONS = /* @__PURE__ */ new Set(["back", "forward"]);
1987
+ PendingSafetyChecks = class extends Error {
1988
+ constructor(callId, checks) {
1989
+ const listed = checks.map((c) => `${c.code ?? "check"}: ${c.message ?? ""}`.trim()).join("; ");
1990
+ super(
1991
+ `computer_call ${callId} needs ${checks.length} safety check(s) acknowledged: ${listed}`
1992
+ );
1993
+ this.callId = callId;
1994
+ this.checks = checks;
1995
+ this.name = "PendingSafetyChecks";
1996
+ }
1997
+ callId;
1998
+ checks;
1999
+ };
2000
+ ACTIONS = {
2001
+ click: (raw) => {
2002
+ const button = String(readField(raw, "button") ?? "left");
2003
+ if (HISTORY_BUTTONS.has(button))
2004
+ return new ComputerAction("history", {
2005
+ direction: button
2006
+ });
2007
+ if (!Object.hasOwn(BUTTONS, button))
2008
+ throw new Error(`unknown mouse button: ${button}`);
2009
+ return new ComputerAction("click", {
2010
+ ...xy(raw),
2011
+ button: BUTTONS[button],
2012
+ count: 1,
2013
+ modifiers: held(raw)
2014
+ });
2015
+ },
2016
+ double_click: (raw) => new ComputerAction("click", {
2017
+ ...xy(raw),
2018
+ button: "left",
2019
+ count: 2,
2020
+ modifiers: held(raw)
2021
+ }),
2022
+ drag: (raw) => new ComputerAction("drag", {
2023
+ path: (readField(raw, "path") ?? []).map(
2024
+ (p) => [toInt(readField(p, "x")), toInt(readField(p, "y"))]
2025
+ ),
2026
+ modifiers: held(raw)
2027
+ }),
2028
+ keypress: (raw) => new ComputerAction("key", {
2029
+ keys: [
2030
+ ...KeyChord.fromKeys(readField(raw, "keys") ?? []).keys
2031
+ ],
2032
+ repeat: 1
2033
+ }),
2034
+ move: (raw) => new ComputerAction("move", { ...xy(raw), modifiers: held(raw) }),
2035
+ scroll: (raw) => new ComputerAction("scroll", {
2036
+ ...xy(raw),
2037
+ dx: toInt(readField(raw, "scroll_x", "scrollX") ?? 0),
2038
+ dy: toInt(readField(raw, "scroll_y", "scrollY") ?? 0),
2039
+ modifiers: held(raw)
2040
+ }),
2041
+ type: (raw) => new ComputerAction("type", { text: String(readField(raw, "text") ?? "") }),
2042
+ wait: () => new ComputerAction("wait", { seconds: WAIT_SECONDS }),
2043
+ screenshot: () => new ComputerAction("screenshot")
2044
+ };
2045
+ OpenAIComputer = class _OpenAIComputer extends NativeComputer {
2046
+ tool() {
2047
+ return { type: "computer" };
2048
+ }
2049
+ owns(item) {
2050
+ return readField(item, "type") === "computer_call";
2051
+ }
2052
+ parse(raw) {
2053
+ const kind = String(readField(raw, "type"));
2054
+ const parser = Object.hasOwn(ACTIONS, kind) ? ACTIONS[kind] : void 0;
2055
+ if (!parser) throw new Error(`unknown computer action: ${kind}`);
2056
+ return parser(raw);
2057
+ }
2058
+ static actionsOf(call) {
2059
+ const batch = readField(call, "actions");
2060
+ if (Array.isArray(batch)) return batch;
2061
+ const single = readField(call, "action");
2062
+ return single === void 0 ? [] : [single];
2063
+ }
2064
+ /** Run a `computer_call`'s actions and return its `computer_call_output`.
2065
+ * Throws `PendingSafetyChecks` (before anything runs) while a check the
2066
+ * model raised is not in `acknowledged`. */
2067
+ async execute(call, acknowledged = []) {
2068
+ const callId = String(readField(call, "call_id", "callId"));
2069
+ const checks = (readField(
2070
+ call,
2071
+ "pending_safety_checks",
2072
+ "pendingSafetyChecks"
2073
+ ) ?? []).map(safetyCheck);
2074
+ const png = await this.runCall(
2075
+ callId,
2076
+ _OpenAIComputer.actionsOf(call),
2077
+ checks,
2078
+ acknowledged
2079
+ );
2080
+ return {
2081
+ type: "computer_call_output",
2082
+ call_id: callId,
2083
+ output: {
2084
+ type: "computer_screenshot",
2085
+ image_url: dataUrl(png),
2086
+ detail: "original"
2087
+ },
2088
+ ...checks.length > 0 ? { acknowledged_safety_checks: checks } : {}
2089
+ };
2090
+ }
2091
+ /** For `openai.tools.computer({ ...computer.aiSdk() })`: `execute` runs a
2092
+ * call's `actions` and returns the screenshot output. A call with pending
2093
+ * safety checks asks for approval first (`needsApproval`), so the AI SDK's
2094
+ * approval flow puts them in front of a person; once approved, `execute`
2095
+ * acknowledges them. */
2096
+ aiSdk() {
2097
+ return {
2098
+ needsApproval: (input) => (input.pendingSafetyChecks ?? []).length > 0,
2099
+ execute: (input) => this.serial(async () => {
2100
+ const checks = (input.pendingSafetyChecks ?? []).map(safetyCheck);
2101
+ const png = await this.runCall(
2102
+ "ai-sdk",
2103
+ input.actions ?? [],
2104
+ checks,
2105
+ checks
2106
+ );
2107
+ return {
2108
+ output: { type: "computer_screenshot", imageUrl: dataUrl(png) },
2109
+ ...checks.length > 0 ? { acknowledgedSafetyChecks: checks } : {}
2110
+ };
2111
+ })
2112
+ };
2113
+ }
2114
+ /** The batch's actions, run after the safety checks clear; the screen after them. */
2115
+ async runCall(callId, rawActions, checks, acknowledged) {
2116
+ const cleared = new Set(acknowledged.map((c) => safetyCheck(c).id));
2117
+ const waiting = checks.filter((c) => !c.id || !cleared.has(c.id));
2118
+ if (waiting.length > 0) throw new PendingSafetyChecks(callId, waiting);
2119
+ const actions = rawActions.map((raw) => this.parse(raw));
2120
+ const results = await this.performAll(actions);
2121
+ const last = actions.at(-1);
2122
+ if (last?.name === "screenshot")
2123
+ return results.at(-1)?.image ?? Buffer.alloc(0);
2124
+ return this.screenshot();
2125
+ }
2126
+ };
2127
+ OpenAIPreviewComputer = class extends OpenAIComputer {
2128
+ tool() {
2129
+ return {
2130
+ type: "computer_use_preview",
2131
+ display_width: this.display.width,
2132
+ display_height: this.display.height,
2133
+ environment: "browser"
2134
+ };
2135
+ }
2136
+ };
2137
+ NativeComputer.register("openai", OpenAIComputer);
2138
+ NativeComputer.register("openai-preview", OpenAIPreviewComputer);
2139
+ }
2140
+ });
2141
+
2142
+ // src/worlds/nativeComputer/index.ts
2143
+ var init_nativeComputer = __esm({
2144
+ "src/worlds/nativeComputer/index.ts"() {
2145
+ "use strict";
2146
+ init_actions();
2147
+ init_base();
2148
+ init_display();
2149
+ init_keys();
2150
+ init_screen();
2151
+ init_trace();
2152
+ init_anthropic();
2153
+ init_openai();
2154
+ }
2155
+ });
2156
+
890
2157
  // src/worlds/sessionContract.ts
891
2158
  function serializeCallBody(body) {
892
2159
  const text2 = JSON.stringify(body);
@@ -940,6 +2207,75 @@ var init_sessionContract = __esm({
940
2207
  }
941
2208
  });
942
2209
 
2210
+ // src/tracing/session.ts
2211
+ var session_exports = {};
2212
+ __export(session_exports, {
2213
+ SESSION_ID_ATTRIBUTE: () => SESSION_ID_ATTRIBUTE,
2214
+ SessionSpanProcessor: () => SessionSpanProcessor,
2215
+ WORLD_SESSION_ID_ATTRIBUTE: () => WORLD_SESSION_ID_ATTRIBUTE,
2216
+ getAmbientSessionId: () => getAmbientSessionId,
2217
+ getCurrentWorldSessionId: () => getCurrentWorldSessionId,
2218
+ withSession: () => withSession,
2219
+ withWorldSession: () => withWorldSession
2220
+ });
2221
+ import { AsyncLocalStorage } from "async_hooks";
2222
+ function getAmbientSessionId() {
2223
+ return currentSessionStorage.getStore();
2224
+ }
2225
+ function getCurrentWorldSessionId() {
2226
+ return currentWorldSessionStorage.getStore();
2227
+ }
2228
+ function runIn(storage, value, fn) {
2229
+ return new Promise((resolve7, reject) => {
2230
+ storage.run(value, () => {
2231
+ Promise.resolve().then(fn).then(resolve7, reject);
2232
+ });
2233
+ });
2234
+ }
2235
+ function withSession(sessionId, fn) {
2236
+ return runIn(currentSessionStorage, sessionId, fn);
2237
+ }
2238
+ function withWorldSession(worldSessionId, fn) {
2239
+ return runIn(
2240
+ currentWorldSessionStorage,
2241
+ worldSessionId,
2242
+ () => withSession(worldSessionId, fn)
2243
+ );
2244
+ }
2245
+ var SESSION_ID_ATTRIBUTE, WORLD_SESSION_ID_ATTRIBUTE, processStorage, currentSessionStorage, currentWorldSessionStorage, SessionSpanProcessor;
2246
+ var init_session = __esm({
2247
+ "src/tracing/session.ts"() {
2248
+ "use strict";
2249
+ SESSION_ID_ATTRIBUTE = "gateway.session.id";
2250
+ WORLD_SESSION_ID_ATTRIBUTE = "gateway.trace.metadata.world_session_id";
2251
+ processStorage = (name) => {
2252
+ const key = /* @__PURE__ */ Symbol.for(`@withgateway/sdk/${name}`);
2253
+ const slots = globalThis;
2254
+ slots[key] ??= new AsyncLocalStorage();
2255
+ return slots[key];
2256
+ };
2257
+ currentSessionStorage = processStorage("session-storage");
2258
+ currentWorldSessionStorage = processStorage("world-session-storage");
2259
+ SessionSpanProcessor = class {
2260
+ onStart(span, _parentContext) {
2261
+ const worldSessionId = getCurrentWorldSessionId();
2262
+ if (worldSessionId)
2263
+ span.setAttribute(WORLD_SESSION_ID_ATTRIBUTE, worldSessionId);
2264
+ const sessionId = getAmbientSessionId();
2265
+ if (!sessionId || span.attributes?.[SESSION_ID_ATTRIBUTE] !== void 0)
2266
+ return;
2267
+ span.setAttribute(SESSION_ID_ATTRIBUTE, sessionId);
2268
+ }
2269
+ onEnd(_span) {
2270
+ }
2271
+ async shutdown() {
2272
+ }
2273
+ async forceFlush() {
2274
+ }
2275
+ };
2276
+ }
2277
+ });
2278
+
943
2279
  // src/worlds/taskRef.ts
944
2280
  var isTaskIdRef, isTaskSpec, taskLabel, assertTaskRef;
945
2281
  var init_taskRef = __esm({
@@ -964,8 +2300,8 @@ var init_taskRef = __esm({
964
2300
  });
965
2301
 
966
2302
  // src/worlds/session.ts
967
- var session_exports = {};
968
- __export(session_exports, {
2303
+ var session_exports2 = {};
2304
+ __export(session_exports2, {
969
2305
  WorldSession: () => WorldSession,
970
2306
  WorldSessionCallError: () => WorldSessionCallError,
971
2307
  WorldSessionTimeout: () => WorldSessionTimeout,
@@ -1019,7 +2355,7 @@ function schemaFromSignature(spec) {
1019
2355
  };
1020
2356
  const inside = /\(([\s\S]*)\)\s*$/.exec(spec.signature.trim())?.[1] ?? "";
1021
2357
  const properties = {};
1022
- const required = [];
2358
+ const required2 = [];
1023
2359
  const params = [];
1024
2360
  let depth = 0;
1025
2361
  let current = "";
@@ -1040,7 +2376,7 @@ function schemaFromSignature(spec) {
1040
2376
  if (!name) continue;
1041
2377
  if (eq === -1) {
1042
2378
  properties[name] = { type: "string" };
1043
- required.push(name);
2379
+ required2.push(name);
1044
2380
  continue;
1045
2381
  }
1046
2382
  const value = param.slice(eq + 1).trim();
@@ -1054,7 +2390,7 @@ function schemaFromSignature(spec) {
1054
2390
  function: {
1055
2391
  name: modelToolName(spec.name),
1056
2392
  description: spec.doc ?? spec.name,
1057
- parameters: { type: "object", properties, required }
2393
+ parameters: { type: "object", properties, required: required2 }
1058
2394
  }
1059
2395
  };
1060
2396
  }
@@ -1123,13 +2459,16 @@ async function runSessions(opts) {
1123
2459
  task = taskLabel(taskRef, session.taskInfo);
1124
2460
  await session.ready();
1125
2461
  const toolkit = await session.toolkit();
1126
- await opts.agent({
1127
- session,
1128
- toolkit,
1129
- instruction: session.instruction ?? (isTaskSpec(taskRef) ? taskRef.instruction : task),
1130
- task,
1131
- taskRef
1132
- });
2462
+ const live = session;
2463
+ await live.withTraceContext(
2464
+ () => opts.agent({
2465
+ session: live,
2466
+ toolkit,
2467
+ instruction: live.instruction ?? (isTaskSpec(taskRef) ? taskRef.instruction : task),
2468
+ task,
2469
+ taskRef
2470
+ })
2471
+ );
1133
2472
  const graded = await session.grade();
1134
2473
  const result = {
1135
2474
  task,
@@ -1167,12 +2506,14 @@ async function runSessions(opts) {
1167
2506
  };
1168
2507
  }
1169
2508
  var READY_TIMEOUT_MS, READY_POLL_MS, CALL_TIMEOUT_MS, CALL_POLL_MS, JUDGED_GRADE_TIMEOUT_MS, JUDGED_GRADE_POLL_MS, EXPORT_PAGE, sleep, modelToolName, WorldSessionTimeout, WorldSessionCallError, WorldSession, OPEN_SESSION_OPTION_KEYS, isOpenSessionOptions;
1170
- var init_session = __esm({
2509
+ var init_session2 = __esm({
1171
2510
  "src/worlds/session.ts"() {
1172
2511
  "use strict";
1173
2512
  init_worlds();
1174
2513
  init_browser();
2514
+ init_nativeComputer();
1175
2515
  init_sessionContract();
2516
+ init_session();
1176
2517
  init_taskRef();
1177
2518
  init_taskRef();
1178
2519
  READY_TIMEOUT_MS = 10 * 6e4;
@@ -1326,6 +2667,12 @@ var init_session = __esm({
1326
2667
  computerUseTools(browser) {
1327
2668
  return computerUseToolkit(browser);
1328
2669
  }
2670
+ /** The browser as a provider's own pixel-based computer-use tool: `anthropic`
2671
+ * (`computer_toolset_20260801`), `openai` (Responses `computer`),
2672
+ * `anthropic-computer-20251124` or `openai-preview`. See `nativeComputer/`. */
2673
+ nativeComputer(browser, provider = "anthropic", options = {}) {
2674
+ return NativeComputer.forProvider(provider, browser, options);
2675
+ }
1329
2676
  /** The session's latest platform state (one request, no waiting). */
1330
2677
  async status() {
1331
2678
  const fresh = await apiRequest(
@@ -1560,6 +2907,21 @@ var init_session = __esm({
1560
2907
  { keepWarm: opts.keepWarm ?? false }
1561
2908
  );
1562
2909
  }
2910
+ /**
2911
+ * Run `fn` as work inside this session: spans it records take `sessionId`
2912
+ * as their session id and carry `world_session_id` trace metadata, so the
2913
+ * agent's traces land in the same session as the platform's traces of this
2914
+ * session's tool calls. A `withSession()` block inside still wins for the
2915
+ * session id. No effect before `tracing.init()`. `runSessions` wraps each
2916
+ * agent call in it.
2917
+ *
2918
+ * ```typescript
2919
+ * await session.withTraceContext(() => myAgent(toolkit, session.instruction));
2920
+ * ```
2921
+ */
2922
+ withTraceContext(fn) {
2923
+ return withWorldSession(this.sessionId, fn);
2924
+ }
1563
2925
  };
1564
2926
  OPEN_SESSION_OPTION_KEYS = /* @__PURE__ */ new Set([
1565
2927
  "task",
@@ -1709,7 +3071,11 @@ function fromResponse(answer, options) {
1709
3071
  const worlds = {};
1710
3072
  for (const [alias, state2] of Object.entries(answer.sessions)) {
1711
3073
  sessions[alias] = new WorldSession(state2.sessionId, state2, options);
1712
- worlds[alias] = { slug: state2.slug, ref: state2.ref };
3074
+ worlds[alias] = {
3075
+ slug: state2.slug,
3076
+ ref: state2.ref,
3077
+ private: state2.private ?? null
3078
+ };
1713
3079
  }
1714
3080
  return new TaskSessions(
1715
3081
  answer.taskId,
@@ -1783,6 +3149,7 @@ async function attachTask(taskId, options = {}) {
1783
3149
  {
1784
3150
  slug: row.slug ?? "",
1785
3151
  ref: null,
3152
+ private: null,
1786
3153
  versionId: row.versionId,
1787
3154
  sessionId: row.sessionId,
1788
3155
  ready: row.ready,
@@ -1812,7 +3179,7 @@ async function attachManifest(manifest, options = {}) {
1812
3179
  Object.fromEntries(
1813
3180
  Object.entries(manifest.sessions).map(([alias, entry]) => [
1814
3181
  alias,
1815
- { slug: entry.slug, ref: entry.ref }
3182
+ { slug: entry.slug, ref: entry.ref, private: entry.private ?? null }
1816
3183
  ])
1817
3184
  )
1818
3185
  );
@@ -1826,12 +3193,13 @@ var init_taskSessions = __esm({
1826
3193
  "use strict";
1827
3194
  init_worlds();
1828
3195
  init_browser();
1829
- init_session();
3196
+ init_session2();
1830
3197
  TASK_SESSIONS = "/api/public/world-task-sessions";
1831
3198
  VERIFIER_REWARD_PREFIX = "x.";
1832
3199
  manifestSession = (s, state2, world) => ({
1833
3200
  slug: world.slug,
1834
3201
  ref: world.ref,
3202
+ private: world.private,
1835
3203
  versionId: state2.versionId,
1836
3204
  sessionId: state2.sessionId,
1837
3205
  ready: state2.ready,
@@ -1866,10 +3234,10 @@ var init_taskSessions = __esm({
1866
3234
  sessions;
1867
3235
  worlds;
1868
3236
  hash;
1869
- /** This alias's `{slug, ref}` as recorded at open/attach — the world a
1870
- * `TaskRun` filing needs to name, without exposing the whole map. */
3237
+ /** This alias's world as recorded at open/attach — what a `TaskRun`
3238
+ * filing needs to name, without exposing the whole map. */
1871
3239
  worldRef(alias) {
1872
- return this.worlds[alias] ?? { slug: "", ref: null };
3240
+ return this.worlds[alias] ?? { slug: "", ref: null, private: null };
1873
3241
  }
1874
3242
  /** The aliases, in the spec's order. */
1875
3243
  get aliases() {
@@ -2233,7 +3601,7 @@ var init_users = __esm({
2233
3601
  });
2234
3602
 
2235
3603
  // src/tracing/identity.ts
2236
- import { AsyncLocalStorage } from "async_hooks";
3604
+ import { AsyncLocalStorage as AsyncLocalStorage2 } from "async_hooks";
2237
3605
  import { isSpanContextValid, trace } from "@opentelemetry/api";
2238
3606
  function resolveUserId() {
2239
3607
  const contextual = currentUserStorage.getStore();
@@ -2247,7 +3615,7 @@ var init_identity = __esm({
2247
3615
  "use strict";
2248
3616
  init_users();
2249
3617
  USER_ID_ATTRIBUTE = "gateway.user.id";
2250
- currentUserStorage = new AsyncLocalStorage();
3618
+ currentUserStorage = new AsyncLocalStorage2();
2251
3619
  IdentitySpanProcessor = class {
2252
3620
  onStart(span, _parentContext) {
2253
3621
  const userId = resolveUserId();
@@ -2265,43 +3633,224 @@ var init_identity = __esm({
2265
3633
  }
2266
3634
  });
2267
3635
 
2268
- // src/tracing/session.ts
2269
- var session_exports2 = {};
2270
- __export(session_exports2, {
2271
- SESSION_ID_ATTRIBUTE: () => SESSION_ID_ATTRIBUTE,
2272
- SessionSpanProcessor: () => SessionSpanProcessor,
2273
- getAmbientSessionId: () => getAmbientSessionId,
2274
- withSession: () => withSession
2275
- });
2276
- import { AsyncLocalStorage as AsyncLocalStorage2 } from "async_hooks";
2277
- function getAmbientSessionId() {
2278
- return currentSessionStorage.getStore();
3636
+ // src/tracing/secrets.ts
3637
+ function jsonOrUndefined(text2) {
3638
+ let parsed;
3639
+ try {
3640
+ parsed = JSON.parse(text2);
3641
+ } catch {
3642
+ return void 0;
3643
+ }
3644
+ if (typeof parsed === "string") return parsed;
3645
+ return parsed !== null && typeof parsed === "object" ? parsed : void 0;
2279
3646
  }
2280
- function withSession(sessionId, fn) {
2281
- return new Promise((resolve7, reject) => {
2282
- currentSessionStorage.run(sessionId, () => {
2283
- Promise.resolve().then(fn).then(resolve7, reject);
2284
- });
3647
+ function encodings(value) {
3648
+ return [value, percentEncoded(value), JSON.stringify(value).slice(1, -1)];
3649
+ }
3650
+ function percentEncoded(value) {
3651
+ try {
3652
+ return encodeURIComponent(value);
3653
+ } catch {
3654
+ return value;
3655
+ }
3656
+ }
3657
+ function union(sets) {
3658
+ return new Set(sets.flatMap((set) => [...set]));
3659
+ }
3660
+ function leaves(value) {
3661
+ if (typeof value === "string") {
3662
+ return [...value].length >= MIN_SECRET_LENGTH ? /* @__PURE__ */ new Set([value]) : /* @__PURE__ */ new Set();
3663
+ }
3664
+ if (Array.isArray(value)) return union(value.map(leaves));
3665
+ if (value === null || typeof value !== "object") return /* @__PURE__ */ new Set();
3666
+ return union(Object.values(value).map(leaves));
3667
+ }
3668
+ function sameAttributes(before, after) {
3669
+ const keys = Object.keys(before);
3670
+ if (keys.length !== Object.keys(after).length) return false;
3671
+ return keys.every(
3672
+ (key) => before[key] === after[key] || sameArray(before[key], after[key])
3673
+ );
3674
+ }
3675
+ function sameArray(before, after) {
3676
+ if (!Array.isArray(before) || !Array.isArray(after)) return false;
3677
+ return before.length === after.length && before.every((item, i) => item === after[i]);
3678
+ }
3679
+ function scrubbedRead(reads, property) {
3680
+ return typeof property === "string" && property in reads ? reads[property] : void 0;
3681
+ }
3682
+ function viewOf(span, reads) {
3683
+ const view = new Proxy(span, {
3684
+ get(target, property) {
3685
+ const read = scrubbedRead(reads, property);
3686
+ if (read) return read();
3687
+ const value = Reflect.get(target, property, target);
3688
+ if (typeof value !== "function") return value;
3689
+ return (...args) => {
3690
+ const result = value.apply(target, args);
3691
+ return result === target ? view : result;
3692
+ };
3693
+ },
3694
+ getOwnPropertyDescriptor(target, property) {
3695
+ const descriptor = Reflect.getOwnPropertyDescriptor(target, property);
3696
+ const read = scrubbedRead(reads, property);
3697
+ if (!read || !descriptor || !("value" in descriptor)) return descriptor;
3698
+ return { ...descriptor, value: read() };
3699
+ }
2285
3700
  });
3701
+ return view;
2286
3702
  }
2287
- var SESSION_ID_ATTRIBUTE, currentSessionStorage, SessionSpanProcessor;
2288
- var init_session2 = __esm({
2289
- "src/tracing/session.ts"() {
3703
+ var SECRET_KEYS, REDACTED2, MIN_SECRET_LENGTH, SpanSecrets, SPAN_SECRETS, SecretRedactingSpanProcessor;
3704
+ var init_secrets = __esm({
3705
+ "src/tracing/secrets.ts"() {
2290
3706
  "use strict";
2291
- SESSION_ID_ATTRIBUTE = "gateway.session.id";
2292
- currentSessionStorage = new AsyncLocalStorage2();
2293
- SessionSpanProcessor = class {
2294
- onStart(span, _parentContext) {
2295
- const sessionId = getAmbientSessionId();
2296
- if (sessionId) {
2297
- span.setAttribute(SESSION_ID_ATTRIBUTE, sessionId);
3707
+ SECRET_KEYS = /* @__PURE__ */ new Set([
3708
+ "authorization_token",
3709
+ "authorizationToken"
3710
+ ]);
3711
+ REDACTED2 = "[redacted: holds a credential]";
3712
+ MIN_SECRET_LENGTH = 8;
3713
+ SpanSecrets = class {
3714
+ constructor(keys = SECRET_KEYS) {
3715
+ this.keys = keys;
3716
+ }
3717
+ keys;
3718
+ isSecret(key) {
3719
+ return this.keys.has(key);
3720
+ }
3721
+ drops(attribute) {
3722
+ return this.mentions(attribute);
3723
+ }
3724
+ strip(value) {
3725
+ if (typeof value === "string") return this.stripNested(value);
3726
+ if (Array.isArray(value)) return value.map((item) => this.strip(item));
3727
+ if (value === null || typeof value !== "object") return value;
3728
+ return Object.fromEntries(
3729
+ Object.entries(value).filter(([key]) => !this.isSecret(key)).map(([key, item]) => [key, this.strip(item)])
3730
+ );
3731
+ }
3732
+ scrubAttribute(value) {
3733
+ try {
3734
+ return this.scrubbedValue(value);
3735
+ } catch {
3736
+ return Array.isArray(value) ? [REDACTED2] : REDACTED2;
2298
3737
  }
2299
3738
  }
2300
- onEnd(_span) {
3739
+ scrubbedValue(value) {
3740
+ if (typeof value === "string") return this.scrubbedText(value);
3741
+ if (!Array.isArray(value)) return value;
3742
+ const results = value.map(
3743
+ (item) => typeof item === "string" ? this.cleaned(item) : { text: item, removed: /* @__PURE__ */ new Set() }
3744
+ );
3745
+ const removed = new Set(results.flatMap((r) => [...r.removed]));
3746
+ const scrubbed = results.map((r) => r.text);
3747
+ const withheld = scrubbed.some(
3748
+ (item) => typeof item === "string" && this.carries(item, removed)
3749
+ );
3750
+ return withheld ? [REDACTED2] : scrubbed;
2301
3751
  }
2302
- async shutdown() {
3752
+ scrubAttributes(attributes) {
3753
+ return Object.fromEntries(
3754
+ Object.entries(attributes).filter(([key]) => !this.drops(key)).map(([key, value]) => [key, this.scrubAttribute(value)])
3755
+ );
2303
3756
  }
2304
- async forceFlush() {
3757
+ mentions(text2) {
3758
+ return [...this.keys].some((key) => text2.includes(key));
3759
+ }
3760
+ scrubbedText(text2) {
3761
+ const { text: cleaned, removed } = this.cleaned(text2);
3762
+ return this.carries(cleaned, removed) ? REDACTED2 : cleaned;
3763
+ }
3764
+ cleaned(text2) {
3765
+ if (!this.mentions(text2)) return { text: text2, removed: /* @__PURE__ */ new Set() };
3766
+ const parsed = jsonOrUndefined(text2);
3767
+ if (parsed === void 0) return { text: REDACTED2, removed: /* @__PURE__ */ new Set() };
3768
+ return {
3769
+ text: JSON.stringify(this.strip(parsed)),
3770
+ removed: this.removed(parsed)
3771
+ };
3772
+ }
3773
+ carries(text2, removed) {
3774
+ if (text2 === REDACTED2 || this.mentions(text2)) return true;
3775
+ return [...removed].some(
3776
+ (value) => encodings(value).some((form) => text2.includes(form))
3777
+ );
3778
+ }
3779
+ removed(value) {
3780
+ if (typeof value === "string") {
3781
+ const nested = this.mentions(value) ? jsonOrUndefined(value) : void 0;
3782
+ return nested === void 0 ? /* @__PURE__ */ new Set() : this.removed(nested);
3783
+ }
3784
+ if (Array.isArray(value)) return union(value.map((v) => this.removed(v)));
3785
+ if (value === null || typeof value !== "object") return /* @__PURE__ */ new Set();
3786
+ return union(
3787
+ Object.entries(value).map(
3788
+ ([key, item]) => this.isSecret(key) ? leaves(item) : this.removed(item)
3789
+ )
3790
+ );
3791
+ }
3792
+ stripNested(text2) {
3793
+ if (!this.mentions(text2)) return text2;
3794
+ const parsed = jsonOrUndefined(text2);
3795
+ if (parsed === void 0) return text2;
3796
+ return JSON.stringify(this.strip(parsed));
3797
+ }
3798
+ };
3799
+ SPAN_SECRETS = new SpanSecrets();
3800
+ SecretRedactingSpanProcessor = class {
3801
+ constructor(inner, secrets = SPAN_SECRETS) {
3802
+ this.inner = inner;
3803
+ this.secrets = secrets;
3804
+ }
3805
+ inner;
3806
+ secrets;
3807
+ views = /* @__PURE__ */ new WeakMap();
3808
+ onStart(span, parentContext) {
3809
+ this.inner.onStart(this.viewFor(span), parentContext);
3810
+ }
3811
+ onEnd(span) {
3812
+ const view = this.viewFor(span);
3813
+ try {
3814
+ void [view.attributes, view.events, view.status];
3815
+ } catch (error) {
3816
+ console.warn(
3817
+ `[gatewaysdk.tracing] Dropped span "${span.name}": could not redact it: ${error?.name}`
3818
+ );
3819
+ return;
3820
+ }
3821
+ this.inner.onEnd(view);
3822
+ }
3823
+ viewFor(span) {
3824
+ const known = this.views.get(span);
3825
+ if (known) return known;
3826
+ const view = viewOf(span, {
3827
+ attributes: () => this.scrubbedAttributes(span.attributes),
3828
+ events: () => span.events.map((event) => this.scrubbedEvent(event)),
3829
+ status: () => this.scrubbedStatus(span.status)
3830
+ });
3831
+ this.views.set(span, view);
3832
+ return view;
3833
+ }
3834
+ forceFlush() {
3835
+ return this.inner.forceFlush();
3836
+ }
3837
+ shutdown() {
3838
+ return this.inner.shutdown();
3839
+ }
3840
+ scrubbedAttributes(attributes) {
3841
+ const clean = this.secrets.scrubAttributes(attributes);
3842
+ return sameAttributes(attributes, clean) ? attributes : clean;
3843
+ }
3844
+ scrubbedStatus(status) {
3845
+ if (!status.message) return status;
3846
+ const message = this.secrets.scrubAttribute(status.message);
3847
+ return message === status.message ? status : { ...status, message };
3848
+ }
3849
+ scrubbedEvent(event) {
3850
+ if (!event.attributes) return event;
3851
+ const attributes = this.scrubbedAttributes(event.attributes);
3852
+ if (attributes === event.attributes) return event;
3853
+ return { ...event, attributes };
2305
3854
  }
2306
3855
  };
2307
3856
  }
@@ -2528,7 +4077,7 @@ var require_package = __commonJS({
2528
4077
  "package.json"(exports, module) {
2529
4078
  module.exports = {
2530
4079
  name: "@withgateway/sdk",
2531
- version: "0.2.9",
4080
+ version: "0.3.0",
2532
4081
  description: "Gateway SDK for TypeScript - A/B experiments, tracing, and observability",
2533
4082
  main: "./dist/index.js",
2534
4083
  module: "./dist/index.mjs",
@@ -2728,7 +4277,7 @@ var require_package = __commonJS({
2728
4277
  });
2729
4278
 
2730
4279
  // src/build/index.ts
2731
- import { createHash } from "crypto";
4280
+ import { createHash as createHash2 } from "crypto";
2732
4281
  function canonicalJson(value) {
2733
4282
  if (value === null || typeof value !== "object") {
2734
4283
  return JSON.stringify(value);
@@ -2740,7 +4289,7 @@ function canonicalJson(value) {
2740
4289
  return `{${entries.map(([k, v]) => `${JSON.stringify(k)}:${canonicalJson(v)}`).join(",")}}`;
2741
4290
  }
2742
4291
  function sha256(text2) {
2743
- return `sha256:${createHash("sha256").update(text2).digest("hex")}`;
4292
+ return `sha256:${createHash2("sha256").update(text2).digest("hex")}`;
2744
4293
  }
2745
4294
  function getRegisteredTools() {
2746
4295
  return [...registeredTools.values()].sort(
@@ -3048,7 +4597,7 @@ function buildProvider(config, logFn) {
3048
4597
  const spanProcessors = [];
3049
4598
  if (config.customSpanProcessors) {
3050
4599
  for (const sp of config.customSpanProcessors) {
3051
- spanProcessors.push(sp);
4600
+ spanProcessors.push(new SecretRedactingSpanProcessor(sp));
3052
4601
  logFn(
3053
4602
  "Added custom span processor: %s",
3054
4603
  sp.constructor?.name ?? "unknown"
@@ -3067,7 +4616,11 @@ function buildProvider(config, logFn) {
3067
4616
  if (config.batch?.maxExportBatchSize) {
3068
4617
  batchConfig.maxExportBatchSize = config.batch.maxExportBatchSize;
3069
4618
  }
3070
- spanProcessors.push(new BatchSpanProcessor(exporter, batchConfig));
4619
+ spanProcessors.push(
4620
+ new SecretRedactingSpanProcessor(
4621
+ new BatchSpanProcessor(exporter, batchConfig)
4622
+ )
4623
+ );
3071
4624
  let provider = new NodeTracerProvider({
3072
4625
  resource: createResource(resourceAttrs)
3073
4626
  });
@@ -3205,7 +4758,8 @@ var init_init = __esm({
3205
4758
  "src/tracing/init.ts"() {
3206
4759
  "use strict";
3207
4760
  init_identity();
3208
- init_session2();
4761
+ init_secrets();
4762
+ init_session();
3209
4763
  init_scores();
3210
4764
  init_build();
3211
4765
  ENV_VARS = {
@@ -3361,7 +4915,7 @@ async function runTask(ref, agent, opts) {
3361
4915
  let extra = {};
3362
4916
  try {
3363
4917
  const invoke = () => agent(taskRun);
3364
- const result = traced ? await (await Promise.resolve().then(() => (init_session2(), session_exports2))).withSession(runId, invoke) : await invoke();
4918
+ const result = traced ? await (await Promise.resolve().then(() => (init_session(), session_exports))).withSession(runId, invoke) : await invoke();
3365
4919
  ({ report, extra } = reportFromResult(result));
3366
4920
  } catch (error) {
3367
4921
  const message = (error instanceof Error ? error.message : String(error)) || "Unknown error";
@@ -3434,7 +4988,7 @@ var init_taskRun = __esm({
3434
4988
  "use strict";
3435
4989
  init_browser();
3436
4990
  init_evals();
3437
- init_session();
4991
+ init_session2();
3438
4992
  init_taskSessions();
3439
4993
  TaskRun = class {
3440
4994
  constructor(runId, instruction, model, sessions, manifest) {
@@ -3743,7 +5297,7 @@ var init_checkoutTarget = __esm({
3743
5297
  });
3744
5298
 
3745
5299
  // src/worlds/worldDir.ts
3746
- import { createHash as createHash2 } from "crypto";
5300
+ import { createHash as createHash3 } from "crypto";
3747
5301
  import * as fs3 from "fs";
3748
5302
  import * as path3 from "path";
3749
5303
  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;
@@ -3853,7 +5407,7 @@ var init_worldDir = __esm({
3853
5407
  * sorted order: the version's identity, byte-compatible with
3854
5408
  * `_archive.compute_content_hash` and Prime Intellect. */
3855
5409
  get contentHash() {
3856
- const hasher = createHash2("sha256");
5410
+ const hasher = createHash3("sha256");
3857
5411
  for (const rel of this.archivePaths) {
3858
5412
  hasher.update(Buffer.from(`file:${rel}`, "utf-8"));
3859
5413
  hasher.update(fs3.readFileSync(path3.join(this.dir, rel)));
@@ -4049,7 +5603,7 @@ __export(hub_exports, {
4049
5603
  snapshotTreeHashes: () => snapshotTreeHashes,
4050
5604
  writeLocalMeta: () => writeLocalMeta
4051
5605
  });
4052
- import { createHash as createHash3 } from "crypto";
5606
+ import { createHash as createHash4 } from "crypto";
4053
5607
  import { gzipSync } from "zlib";
4054
5608
  import * as fs5 from "fs";
4055
5609
  import * as path5 from "path";
@@ -4161,7 +5715,7 @@ function writeLocalMeta(dir, meta) {
4161
5715
  function snapshotTreeHashes(dir) {
4162
5716
  const out = {};
4163
5717
  for (const relPath of collectArchiveRelPaths(dir)) {
4164
- out[relPath] = createHash3("sha256").update(fs5.readFileSync(path5.join(dir, relPath))).digest("hex");
5718
+ out[relPath] = createHash4("sha256").update(fs5.readFileSync(path5.join(dir, relPath))).digest("hex");
4165
5719
  }
4166
5720
  return out;
4167
5721
  }
@@ -4207,7 +5761,7 @@ function buildFileManifest(dir) {
4207
5761
  path: relPath,
4208
5762
  isDirectory: false,
4209
5763
  size: payload.length,
4210
- sha256: createHash3("sha256").update(payload).digest("hex")
5764
+ sha256: createHash4("sha256").update(payload).digest("hex")
4211
5765
  };
4212
5766
  });
4213
5767
  }
@@ -4432,7 +5986,7 @@ var init_hub = __esm({
4432
5986
  tracked;
4433
5987
  declared;
4434
5988
  };
4435
- sha256b64 = (data) => createHash3("sha256").update(data).digest("base64");
5989
+ sha256b64 = (data) => createHash4("sha256").update(data).digest("base64");
4436
5990
  DetachedPushError = class extends Error {
4437
5991
  constructor(dir, tag) {
4438
5992
  super(
@@ -5059,7 +6613,7 @@ var init_json = __esm({
5059
6613
  });
5060
6614
 
5061
6615
  // src/worlds/transforms.ts
5062
- import { createHash as createHash4 } from "crypto";
6616
+ import { createHash as createHash5 } from "crypto";
5063
6617
  function parseTransform(name) {
5064
6618
  const simple = Object.prototype.hasOwnProperty.call(SIMPLE, name) ? SIMPLE[name] : void 0;
5065
6619
  if (simple) return simple;
@@ -5097,7 +6651,7 @@ var init_transforms = __esm({
5097
6651
  return at === -1 ? "" : value.slice(at + 1).toLowerCase();
5098
6652
  };
5099
6653
  stripPrefix = (prefix) => (value) => value.startsWith(prefix) ? value.slice(prefix.length) : value;
5100
- hex = (algorithm, value) => createHash4(algorithm).update(value, "utf8").digest("hex");
6654
+ hex = (algorithm, value) => createHash5(algorithm).update(value, "utf8").digest("hex");
5101
6655
  SIMPLE = {
5102
6656
  lower: (value) => value.toLowerCase(),
5103
6657
  upper: (value) => value.toUpperCase(),
@@ -5121,7 +6675,7 @@ var init_transforms = __esm({
5121
6675
  });
5122
6676
 
5123
6677
  // src/worlds/redaction.ts
5124
- import { createHash as createHash5 } from "crypto";
6678
+ import { createHash as createHash6 } from "crypto";
5125
6679
  function pyText(value) {
5126
6680
  if (typeof value === "string") return value;
5127
6681
  if (Number.isInteger(value)) return String(value);
@@ -5130,7 +6684,7 @@ function pyText(value) {
5130
6684
  return pyFloatRepr(value);
5131
6685
  }
5132
6686
  function hashForm(slug, plaintext) {
5133
- return "sha256:" + createHash5("sha256").update(`${slug}:${pyText(plaintext)}`, "utf8").digest("hex");
6687
+ return "sha256:" + createHash6("sha256").update(`${slug}:${pyText(plaintext)}`, "utf8").digest("hex");
5134
6688
  }
5135
6689
  function preserveForm(slug, plaintext) {
5136
6690
  const kind = typeof plaintext === "string" ? "str" : isInt(plaintext) ? "int" : "float";
@@ -5139,12 +6693,12 @@ function preserveForm(slug, plaintext) {
5139
6693
  }
5140
6694
  function shapeText(slug, text2, kind) {
5141
6695
  const seed = Buffer.from(`${slug}:${text2}`, "utf8");
5142
- let digest = createHash5("sha256").update(seed).digest();
6696
+ let digest = createHash6("sha256").update(seed).digest();
5143
6697
  let cursor = 0;
5144
6698
  const out = [];
5145
6699
  for (const char of text2) {
5146
6700
  if (cursor === digest.length) {
5147
- digest = createHash5("sha256").update(Buffer.concat([digest, seed])).digest();
6701
+ digest = createHash6("sha256").update(Buffer.concat([digest, seed])).digest();
5148
6702
  cursor = 0;
5149
6703
  }
5150
6704
  const byte = digest[cursor];
@@ -6043,7 +7597,7 @@ if (fn) {
6043
7597
  });
6044
7598
 
6045
7599
  // src/cli/platform/worldData/batches.ts
6046
- import { createHash as createHash6 } from "crypto";
7600
+ import { createHash as createHash7 } from "crypto";
6047
7601
  import * as fs11 from "fs";
6048
7602
  function isSettled(status) {
6049
7603
  if (!TERMINAL_STATES.has(status.state)) return false;
@@ -6054,7 +7608,7 @@ function uploadHeadersFor(gz) {
6054
7608
  return {
6055
7609
  "content-type": "application/gzip",
6056
7610
  "content-length": String(gz.length),
6057
- "x-amz-checksum-sha256": createHash6("sha256").update(gz).digest("base64")
7611
+ "x-amz-checksum-sha256": createHash7("sha256").update(gz).digest("base64")
6058
7612
  };
6059
7613
  }
6060
7614
  async function forEachLimited(items, limit, fn) {
@@ -6257,7 +7811,7 @@ var init_batches = __esm({
6257
7811
  });
6258
7812
 
6259
7813
  // src/cli/platform/worldData/chunker.ts
6260
- import { createHash as createHash7 } from "crypto";
7814
+ import { createHash as createHash8 } from "crypto";
6261
7815
  import { deflateRawSync } from "zlib";
6262
7816
  function chunkLine(row, declared) {
6263
7817
  if (declared !== null) return dumps(row.row) + "\n";
@@ -6298,12 +7852,12 @@ function finishChunk(ordinal, raw, rows, entity, firstRow = 0) {
6298
7852
  const gz = gzipDeterministic(raw, { name: chunkName(ordinal) });
6299
7853
  return {
6300
7854
  ordinal,
6301
- digest: createHash7("sha256").update(gz).digest("hex"),
7855
+ digest: createHash8("sha256").update(gz).digest("hex"),
6302
7856
  bytes: gz.length,
6303
7857
  rows,
6304
7858
  entity,
6305
7859
  rawBytes: raw.length,
6306
- contentSha256: createHash7("sha256").update(raw).digest("hex"),
7860
+ contentSha256: createHash8("sha256").update(raw).digest("hex"),
6307
7861
  firstRow,
6308
7862
  gz
6309
7863
  };
@@ -6640,7 +8194,7 @@ var init_ingest = __esm({
6640
8194
  });
6641
8195
 
6642
8196
  // src/worlds/editSessions.ts
6643
- var WORLDS, WorldEditClient;
8197
+ var WORLDS, WorldEditClient, TASK_EDITS, TaskEditClient;
6644
8198
  var init_editSessions = __esm({
6645
8199
  "src/worlds/editSessions.ts"() {
6646
8200
  "use strict";
@@ -6672,6 +8226,22 @@ var init_editSessions = __esm({
6672
8226
  return apiRequest(this.options, "POST", `${WORLDS}/${encodeURIComponent(slug)}/edits/rollback`, input);
6673
8227
  }
6674
8228
  };
8229
+ TASK_EDITS = "/api/public/world-task-edits";
8230
+ TaskEditClient = class {
8231
+ constructor(options = {}) {
8232
+ this.options = options;
8233
+ }
8234
+ options;
8235
+ status(task) {
8236
+ return apiRequest(this.options, "POST", `${TASK_EDITS}/status`, { task });
8237
+ }
8238
+ close(task, input = {}) {
8239
+ return apiRequest(this.options, "POST", `${TASK_EDITS}/close`, { task, ...input });
8240
+ }
8241
+ rollback(task, input) {
8242
+ return apiRequest(this.options, "POST", `${TASK_EDITS}/rollback`, { task, ...input });
8243
+ }
8244
+ };
6675
8245
  }
6676
8246
  });
6677
8247
 
@@ -6767,6 +8337,10 @@ var init_dryRun = __esm({
6767
8337
  // src/worlds/index.ts
6768
8338
  var worlds_exports = {};
6769
8339
  __export(worlds_exports, {
8340
+ ACTION_NAMES: () => ACTION_NAMES,
8341
+ ActionTracer: () => ActionTracer,
8342
+ AnthropicComputer: () => AnthropicComputer,
8343
+ AnthropicComputer20251124: () => AnthropicComputer20251124,
6770
8344
  ApiError: () => ApiError,
6771
8345
  BROWSER_GONE_PATTERNS: () => BROWSER_GONE_PATTERNS,
6772
8346
  BROWSER_TIERS: () => BROWSER_TIERS,
@@ -6778,11 +8352,13 @@ __export(worlds_exports, {
6778
8352
  CALL_BODY_LIMIT_LABEL: () => CALL_BODY_LIMIT_LABEL,
6779
8353
  COMPUTER_USE_SPECS: () => COMPUTER_USE_SPECS,
6780
8354
  CheckoutProvenance: () => CheckoutProvenance,
8355
+ ComputerAction: () => ComputerAction,
6781
8356
  DEFAULT_BRANCH: () => DEFAULT_BRANCH,
6782
8357
  DEFAULT_VIEWPORT: () => DEFAULT_VIEWPORT,
6783
8358
  DRY_RUN_AGENT: () => DRY_RUN_AGENT,
6784
8359
  DRY_RUN_KIND: () => DRY_RUN_KIND,
6785
8360
  DetachedPushError: () => DetachedPushError,
8361
+ Display: () => Display,
6786
8362
  DryRunOutcome: () => DryRunOutcome,
6787
8363
  EVENT_BATCH_SIZE: () => EVENT_BATCH_SIZE,
6788
8364
  EVENT_FLUSH_INTERVAL_MS: () => EVENT_FLUSH_INTERVAL_MS,
@@ -6792,19 +8368,30 @@ __export(worlds_exports, {
6792
8368
  GatewayEvalsClient: () => GatewayEvalsClient,
6793
8369
  HostedDryRunClient: () => HostedDryRunClient,
6794
8370
  IDLE_WARNING_MINUTES: () => IDLE_WARNING_MINUTES,
8371
+ KEY_NAMES: () => KEY_NAMES,
8372
+ KeyChord: () => KeyChord,
8373
+ NOT_EXECUTED: () => NOT_EXECUTED,
6795
8374
  NO_GRADER_REASON: () => NO_GRADER_REASON,
8375
+ NativeComputer: () => NativeComputer,
8376
+ OpenAIComputer: () => OpenAIComputer,
8377
+ OpenAIPreviewComputer: () => OpenAIPreviewComputer,
6796
8378
  PLATFORM_TIMEOUT_DEFAULT_MS: () => PLATFORM_TIMEOUT_DEFAULT_MS,
6797
8379
  PLATFORM_TIMEOUT_ENV: () => PLATFORM_TIMEOUT_ENV,
8380
+ PendingSafetyChecks: () => PendingSafetyChecks,
6798
8381
  PlatformTransport: () => PlatformTransport,
6799
8382
  PushSlugConflict: () => PushSlugConflict,
6800
8383
  RECOVER_BUDGET_MS: () => RECOVER_BUDGET_MS,
6801
8384
  SANDBOX_REQUEST_TIMEOUT_MS: () => SANDBOX_REQUEST_TIMEOUT_MS,
8385
+ SECRET_KEY: () => SECRET_KEY,
6802
8386
  SESSION_STATES: () => SESSION_STATES,
8387
+ SPAN_PREFIX: () => SPAN_PREFIX,
6803
8388
  STATUS_WAIT_CAP_SECONDS: () => STATUS_WAIT_CAP_SECONDS,
6804
8389
  STRIP_PREFIX: () => STRIP_PREFIX,
6805
8390
  SURFACE_KINDS: () => SURFACE_KINDS,
8391
+ Screen: () => Screen,
6806
8392
  SecretScrubber: () => SecretScrubber,
6807
8393
  TRANSFORMS: () => TRANSFORMS,
8394
+ TaskEditClient: () => TaskEditClient,
6808
8395
  TaskRun: () => TaskRun,
6809
8396
  TaskSessions: () => TaskSessions,
6810
8397
  TransportCause: () => TransportCause,
@@ -6877,6 +8464,7 @@ __export(worlds_exports, {
6877
8464
  parseTransform: () => parseTransform,
6878
8465
  parseWorldTaskRefs: () => parseWorldTaskRefs,
6879
8466
  platformTimeoutMs: () => platformTimeoutMs,
8467
+ playwrightKey: () => playwrightKey,
6880
8468
  preserveForm: () => preserveForm,
6881
8469
  propose: () => propose,
6882
8470
  pull: () => pull,
@@ -6886,6 +8474,7 @@ __export(worlds_exports, {
6886
8474
  pyText: () => pyText,
6887
8475
  queryRows: () => queryRows,
6888
8476
  queryRowsSearch: () => queryRowsSearch,
8477
+ readField: () => readField,
6889
8478
  readLocalMeta: () => readLocalMeta,
6890
8479
  readToolCallRecords: () => readToolCallRecords,
6891
8480
  rebaseConflicts: () => rebaseConflicts,
@@ -7134,7 +8723,7 @@ var init_worlds = __esm({
7134
8723
  "src/worlds/index.ts"() {
7135
8724
  init_transport();
7136
8725
  init_transport();
7137
- init_session();
8726
+ init_session2();
7138
8727
  init_sessionList();
7139
8728
  init_sessionContract();
7140
8729
  init_taskRef();
@@ -7146,6 +8735,7 @@ var init_worlds = __esm({
7146
8735
  init_evals();
7147
8736
  init_browser();
7148
8737
  init_browserReconnect();
8738
+ init_nativeComputer();
7149
8739
  init_hub();
7150
8740
  init_validate();
7151
8741
  init_describe();
@@ -7212,7 +8802,7 @@ var init_worlds = __esm({
7212
8802
  * worlds/session.ts.
7213
8803
  */
7214
8804
  async open(task, opts = {}) {
7215
- const { openSession: openSession2 } = await Promise.resolve().then(() => (init_session(), session_exports));
8805
+ const { openSession: openSession2 } = await Promise.resolve().then(() => (init_session2(), session_exports2));
7216
8806
  return openSession2(this.slug, {
7217
8807
  task,
7218
8808
  versionId: this.version.versionId,
@@ -7246,6 +8836,10 @@ var init_worlds = __esm({
7246
8836
  });
7247
8837
  init_worlds();
7248
8838
  export {
8839
+ ACTION_NAMES,
8840
+ ActionTracer,
8841
+ AnthropicComputer,
8842
+ AnthropicComputer20251124,
7249
8843
  ApiError,
7250
8844
  BROWSER_GONE_PATTERNS,
7251
8845
  BROWSER_TIERS,
@@ -7257,11 +8851,13 @@ export {
7257
8851
  CALL_BODY_LIMIT_LABEL,
7258
8852
  COMPUTER_USE_SPECS,
7259
8853
  CheckoutProvenance,
8854
+ ComputerAction,
7260
8855
  DEFAULT_BRANCH,
7261
8856
  DEFAULT_VIEWPORT,
7262
8857
  DRY_RUN_AGENT,
7263
8858
  DRY_RUN_KIND,
7264
8859
  DetachedPushError,
8860
+ Display,
7265
8861
  DryRunOutcome,
7266
8862
  EVENT_BATCH_SIZE,
7267
8863
  EVENT_FLUSH_INTERVAL_MS,
@@ -7271,19 +8867,30 @@ export {
7271
8867
  GatewayEvalsClient,
7272
8868
  HostedDryRunClient,
7273
8869
  IDLE_WARNING_MINUTES,
8870
+ KEY_NAMES,
8871
+ KeyChord,
8872
+ NOT_EXECUTED,
7274
8873
  NO_GRADER_REASON,
8874
+ NativeComputer,
8875
+ OpenAIComputer,
8876
+ OpenAIPreviewComputer,
7275
8877
  PLATFORM_TIMEOUT_DEFAULT_MS,
7276
8878
  PLATFORM_TIMEOUT_ENV,
8879
+ PendingSafetyChecks,
7277
8880
  PlatformTransport,
7278
8881
  PushSlugConflict,
7279
8882
  RECOVER_BUDGET_MS,
7280
8883
  SANDBOX_REQUEST_TIMEOUT_MS,
8884
+ SECRET_KEY,
7281
8885
  SESSION_STATES,
8886
+ SPAN_PREFIX,
7282
8887
  STATUS_WAIT_CAP_SECONDS,
7283
8888
  STRIP_PREFIX,
7284
8889
  SURFACE_KINDS,
8890
+ Screen,
7285
8891
  SecretScrubber,
7286
8892
  TRANSFORMS,
8893
+ TaskEditClient,
7287
8894
  TaskRun,
7288
8895
  TaskSessions,
7289
8896
  TransportCause,
@@ -7356,6 +8963,7 @@ export {
7356
8963
  parseTransform,
7357
8964
  parseWorldTaskRefs,
7358
8965
  platformTimeoutMs,
8966
+ playwrightKey,
7359
8967
  preserveForm,
7360
8968
  propose,
7361
8969
  pull,
@@ -7365,6 +8973,7 @@ export {
7365
8973
  pyText,
7366
8974
  queryRows,
7367
8975
  queryRowsSearch,
8976
+ readField,
7368
8977
  readLocalMeta,
7369
8978
  readToolCallRecords,
7370
8979
  rebaseConflicts,