@withgateway/sdk 0.2.9 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. package/README.md +5 -1
  2. package/dist/cli.js +3812 -1158
  3. package/dist/cli.js.map +1 -1
  4. package/dist/cli.mjs +3796 -1142
  5. package/dist/cli.mjs.map +1 -1
  6. package/dist/files/index.d.mts +1 -0
  7. package/dist/files/index.d.ts +1 -0
  8. package/dist/files/index.js +1358 -21
  9. package/dist/files/index.js.map +1 -1
  10. package/dist/files/index.mjs +1356 -13
  11. package/dist/files/index.mjs.map +1 -1
  12. package/dist/{index-BO2SNSgy.d.ts → index-CBqbB_0J.d.ts} +95 -46
  13. package/dist/{index-Cz8Q6Keo.d.mts → index-D-AMnAMa.d.mts} +95 -46
  14. package/dist/index.d.mts +4 -3
  15. package/dist/index.d.ts +4 -3
  16. package/dist/index.js +1942 -177
  17. package/dist/index.js.map +1 -1
  18. package/dist/index.mjs +1890 -146
  19. package/dist/index.mjs.map +1 -1
  20. package/dist/media-CbcAfQvd.d.mts +83 -0
  21. package/dist/media-CbcAfQvd.d.ts +83 -0
  22. package/dist/traces/index.d.mts +1 -0
  23. package/dist/traces/index.d.ts +1 -0
  24. package/dist/traces/index.js +1355 -18
  25. package/dist/traces/index.js.map +1 -1
  26. package/dist/traces/index.mjs +1353 -10
  27. package/dist/traces/index.mjs.map +1 -1
  28. package/dist/tracing/index.d.mts +2 -1
  29. package/dist/tracing/index.d.ts +2 -1
  30. package/dist/tracing/index.js +550 -30
  31. package/dist/tracing/index.js.map +1 -1
  32. package/dist/tracing/index.mjs +539 -29
  33. package/dist/tracing/index.mjs.map +1 -1
  34. package/dist/worlds/index.d.mts +648 -80
  35. package/dist/worlds/index.d.ts +648 -80
  36. package/dist/worlds/index.js +1875 -145
  37. package/dist/worlds/index.js.map +1 -1
  38. package/dist/worlds/index.mjs +1861 -131
  39. package/dist/worlds/index.mjs.map +1 -1
  40. package/package.json +1 -1
  41. package/runtime/gatewaysdk/environment/schema/api.py +43 -62
  42. package/runtime/gatewaysdk/environment/schema/cast.py +31 -4
  43. package/runtime/gatewaysdk/environment/schema/grading.py +1 -5
  44. package/runtime/gatewaysdk/environment/schema/host.py +53 -90
  45. package/runtime/gatewaysdk/environment/schema/local.py +15 -7
  46. package/runtime/gatewaysdk/environment/schema/platform.py +1 -7
  47. package/runtime/gatewaysdk/environment/schema/runtime.py +9 -9
  48. package/runtime/gatewaysdk/environment/schema/skills/connector-schema-authoring/SKILL.md +3 -3
  49. package/runtime/gatewaysdk/environment/schema/skills/world-data-ingestion/SKILL.md +2 -2
  50. package/runtime/gatewaysdk/environment/schema/skills/worlds-getting-started/SKILL.md +13 -13
  51. package/runtime/gatewaysdk/environment/schema/skills/worlds-getting-started/references/cli-mcp-map.md +2 -1
  52. package/runtime/gatewaysdk/environment/schema/tasks.py +25 -1
  53. package/skills/connector-schema-authoring/SKILL.md +3 -3
  54. package/skills/connector-schema-authoring/connector-worlds.md +12 -5
  55. package/skills/connector-schema-authoring/world-schema.md +8 -0
  56. package/skills/world-data-ingestion/SKILL.md +2 -2
  57. package/skills/worlds-getting-started/SKILL.md +13 -13
  58. package/skills/worlds-getting-started/references/cli-mcp-map.md +2 -1
@@ -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;
@@ -882,8 +886,1271 @@ var init_browser = __esm({
882
886
  signature: "browser_back()",
883
887
  doc: "Go back one page in history."
884
888
  }
885
- ];
886
- str = (v, fallback) => typeof v === "string" && v.length > 0 ? v : fallback;
889
+ ];
890
+ str = (v, fallback) => typeof v === "string" && v.length > 0 ? v : fallback;
891
+ }
892
+ });
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();
887
2154
  }
888
2155
  });
889
2156
 
@@ -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",
@@ -1681,6 +3043,28 @@ var init_tasks = __esm({
1681
3043
  }
1682
3044
  });
1683
3045
 
3046
+ // src/worlds/surfaceDescriptor.ts
3047
+ function surfaceDescriptor(s) {
3048
+ return {
3049
+ surfaces: surfaceKinds(s),
3050
+ ...s.api ? { api: { url: s.api.url, ...s.api.token ? { token: s.api.token } : {} } } : {},
3051
+ ...s.ui ? { ui: { url: s.ui.url, entry: uiEntryUrl(s.ui), apiPath: s.ui.apiPath ?? null } } : {},
3052
+ ...s.browser ? {
3053
+ browser: {
3054
+ wsUrl: s.browser.wsUrl,
3055
+ viewport: s.browser.viewport,
3056
+ ...s.browser.tier ? { tier: s.browser.tier } : {}
3057
+ }
3058
+ } : {}
3059
+ };
3060
+ }
3061
+ var init_surfaceDescriptor = __esm({
3062
+ "src/worlds/surfaceDescriptor.ts"() {
3063
+ "use strict";
3064
+ init_browser();
3065
+ }
3066
+ });
3067
+
1684
3068
  // src/worlds/taskSessions.ts
1685
3069
  function aggregateTaskGrade(worlds) {
1686
3070
  const rewards = {};
@@ -1709,7 +3093,11 @@ function fromResponse(answer, options) {
1709
3093
  const worlds = {};
1710
3094
  for (const [alias, state2] of Object.entries(answer.sessions)) {
1711
3095
  sessions[alias] = new WorldSession(state2.sessionId, state2, options);
1712
- worlds[alias] = { slug: state2.slug, ref: state2.ref };
3096
+ worlds[alias] = {
3097
+ slug: state2.slug,
3098
+ ref: state2.ref,
3099
+ private: state2.private ?? null
3100
+ };
1713
3101
  }
1714
3102
  return new TaskSessions(
1715
3103
  answer.taskId,
@@ -1783,6 +3171,7 @@ async function attachTask(taskId, options = {}) {
1783
3171
  {
1784
3172
  slug: row.slug ?? "",
1785
3173
  ref: null,
3174
+ private: null,
1786
3175
  versionId: row.versionId,
1787
3176
  sessionId: row.sessionId,
1788
3177
  ready: row.ready,
@@ -1812,7 +3201,7 @@ async function attachManifest(manifest, options = {}) {
1812
3201
  Object.fromEntries(
1813
3202
  Object.entries(manifest.sessions).map(([alias, entry]) => [
1814
3203
  alias,
1815
- { slug: entry.slug, ref: entry.ref }
3204
+ { slug: entry.slug, ref: entry.ref, private: entry.private ?? null }
1816
3205
  ])
1817
3206
  )
1818
3207
  );
@@ -1826,28 +3215,19 @@ var init_taskSessions = __esm({
1826
3215
  "use strict";
1827
3216
  init_worlds();
1828
3217
  init_browser();
1829
- init_session();
3218
+ init_surfaceDescriptor();
3219
+ init_session2();
1830
3220
  TASK_SESSIONS = "/api/public/world-task-sessions";
1831
3221
  VERIFIER_REWARD_PREFIX = "x.";
1832
3222
  manifestSession = (s, state2, world) => ({
1833
3223
  slug: world.slug,
1834
3224
  ref: world.ref,
3225
+ private: world.private,
1835
3226
  versionId: state2.versionId,
1836
3227
  sessionId: state2.sessionId,
1837
3228
  ready: state2.ready,
1838
3229
  state: state2.state,
1839
- surfaces: surfaceKinds(s),
1840
- ...s.api ? {
1841
- api: { url: s.api.url, ...s.api.token ? { token: s.api.token } : {} }
1842
- } : {},
1843
- ...s.ui ? {
1844
- ui: {
1845
- url: s.ui.url,
1846
- entry: uiEntryUrl(s.ui),
1847
- apiPath: s.ui.apiPath ?? null
1848
- }
1849
- } : {},
1850
- ...s.browser ? { browser: { wsUrl: s.browser.wsUrl, viewport: s.browser.viewport } } : {}
3230
+ ...surfaceDescriptor(s)
1851
3231
  });
1852
3232
  TaskSessions = class {
1853
3233
  constructor(taskId, taskVersion, name, instruction, sessions, worlds, hash = null) {
@@ -1866,10 +3246,10 @@ var init_taskSessions = __esm({
1866
3246
  sessions;
1867
3247
  worlds;
1868
3248
  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. */
3249
+ /** This alias's world as recorded at open/attach — what a `TaskRun`
3250
+ * filing needs to name, without exposing the whole map. */
1871
3251
  worldRef(alias) {
1872
- return this.worlds[alias] ?? { slug: "", ref: null };
3252
+ return this.worlds[alias] ?? { slug: "", ref: null, private: null };
1873
3253
  }
1874
3254
  /** The aliases, in the spec's order. */
1875
3255
  get aliases() {
@@ -2026,6 +3406,49 @@ var init_evals = __esm({
2026
3406
  }
2027
3407
  });
2028
3408
 
3409
+ // src/tracing/prerequisites.ts
3410
+ function getEnv(key) {
3411
+ const value = process.env[key];
3412
+ return value ? value : void 0;
3413
+ }
3414
+ function isGatewayConfigured() {
3415
+ return !!(getEnv(GATEWAY_ENV.HOST) && getEnv(GATEWAY_ENV.PUBLIC_KEY) && getEnv(GATEWAY_ENV.SECRET_KEY));
3416
+ }
3417
+ var GATEWAY_ENV, OPENTELEMETRY_PEERS, MODULE_NOT_FOUND, OpenTelemetryMissing;
3418
+ var init_prerequisites = __esm({
3419
+ "src/tracing/prerequisites.ts"() {
3420
+ "use strict";
3421
+ GATEWAY_ENV = {
3422
+ HOST: "GATEWAY_HOST",
3423
+ PUBLIC_KEY: "GATEWAY_PUBLIC_KEY",
3424
+ SECRET_KEY: "GATEWAY_SECRET_KEY",
3425
+ ENDPOINT: "GATEWAY_OTLP_ENDPOINT"
3426
+ };
3427
+ OPENTELEMETRY_PEERS = [
3428
+ "@opentelemetry/api",
3429
+ "@opentelemetry/exporter-trace-otlp-http",
3430
+ "@opentelemetry/resources",
3431
+ "@opentelemetry/sdk-trace-base",
3432
+ "@opentelemetry/sdk-trace-node"
3433
+ ];
3434
+ MODULE_NOT_FOUND = /* @__PURE__ */ new Set(["MODULE_NOT_FOUND", "ERR_MODULE_NOT_FOUND"]);
3435
+ OpenTelemetryMissing = class _OpenTelemetryMissing extends Error {
3436
+ constructor() {
3437
+ super(
3438
+ `OpenTelemetry packages not found. Install them with:
3439
+ npm install ${OPENTELEMETRY_PEERS.join(" ")}`
3440
+ );
3441
+ this.name = "OpenTelemetryMissing";
3442
+ }
3443
+ static explains(error) {
3444
+ if (error instanceof _OpenTelemetryMissing) return true;
3445
+ const { code, message } = error ?? {};
3446
+ return MODULE_NOT_FOUND.has(String(code)) && String(message).includes("@opentelemetry/");
3447
+ }
3448
+ };
3449
+ }
3450
+ });
3451
+
2029
3452
  // src/users/index.ts
2030
3453
  function parseEvent(payload) {
2031
3454
  return {
@@ -2233,7 +3656,7 @@ var init_users = __esm({
2233
3656
  });
2234
3657
 
2235
3658
  // src/tracing/identity.ts
2236
- import { AsyncLocalStorage } from "async_hooks";
3659
+ import { AsyncLocalStorage as AsyncLocalStorage2 } from "async_hooks";
2237
3660
  import { isSpanContextValid, trace } from "@opentelemetry/api";
2238
3661
  function resolveUserId() {
2239
3662
  const contextual = currentUserStorage.getStore();
@@ -2247,7 +3670,7 @@ var init_identity = __esm({
2247
3670
  "use strict";
2248
3671
  init_users();
2249
3672
  USER_ID_ATTRIBUTE = "gateway.user.id";
2250
- currentUserStorage = new AsyncLocalStorage();
3673
+ currentUserStorage = new AsyncLocalStorage2();
2251
3674
  IdentitySpanProcessor = class {
2252
3675
  onStart(span, _parentContext) {
2253
3676
  const userId = resolveUserId();
@@ -2265,43 +3688,224 @@ var init_identity = __esm({
2265
3688
  }
2266
3689
  });
2267
3690
 
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();
3691
+ // src/tracing/secrets.ts
3692
+ function jsonOrUndefined(text2) {
3693
+ let parsed;
3694
+ try {
3695
+ parsed = JSON.parse(text2);
3696
+ } catch {
3697
+ return void 0;
3698
+ }
3699
+ if (typeof parsed === "string") return parsed;
3700
+ return parsed !== null && typeof parsed === "object" ? parsed : void 0;
2279
3701
  }
2280
- function withSession(sessionId, fn) {
2281
- return new Promise((resolve7, reject) => {
2282
- currentSessionStorage.run(sessionId, () => {
2283
- Promise.resolve().then(fn).then(resolve7, reject);
2284
- });
3702
+ function encodings(value) {
3703
+ return [value, percentEncoded(value), JSON.stringify(value).slice(1, -1)];
3704
+ }
3705
+ function percentEncoded(value) {
3706
+ try {
3707
+ return encodeURIComponent(value);
3708
+ } catch {
3709
+ return value;
3710
+ }
3711
+ }
3712
+ function union(sets) {
3713
+ return new Set(sets.flatMap((set) => [...set]));
3714
+ }
3715
+ function leaves(value) {
3716
+ if (typeof value === "string") {
3717
+ return [...value].length >= MIN_SECRET_LENGTH ? /* @__PURE__ */ new Set([value]) : /* @__PURE__ */ new Set();
3718
+ }
3719
+ if (Array.isArray(value)) return union(value.map(leaves));
3720
+ if (value === null || typeof value !== "object") return /* @__PURE__ */ new Set();
3721
+ return union(Object.values(value).map(leaves));
3722
+ }
3723
+ function sameAttributes(before, after) {
3724
+ const keys = Object.keys(before);
3725
+ if (keys.length !== Object.keys(after).length) return false;
3726
+ return keys.every(
3727
+ (key) => before[key] === after[key] || sameArray(before[key], after[key])
3728
+ );
3729
+ }
3730
+ function sameArray(before, after) {
3731
+ if (!Array.isArray(before) || !Array.isArray(after)) return false;
3732
+ return before.length === after.length && before.every((item, i) => item === after[i]);
3733
+ }
3734
+ function scrubbedRead(reads, property) {
3735
+ return typeof property === "string" && property in reads ? reads[property] : void 0;
3736
+ }
3737
+ function viewOf(span, reads) {
3738
+ const view = new Proxy(span, {
3739
+ get(target, property) {
3740
+ const read = scrubbedRead(reads, property);
3741
+ if (read) return read();
3742
+ const value = Reflect.get(target, property, target);
3743
+ if (typeof value !== "function") return value;
3744
+ return (...args) => {
3745
+ const result = value.apply(target, args);
3746
+ return result === target ? view : result;
3747
+ };
3748
+ },
3749
+ getOwnPropertyDescriptor(target, property) {
3750
+ const descriptor = Reflect.getOwnPropertyDescriptor(target, property);
3751
+ const read = scrubbedRead(reads, property);
3752
+ if (!read || !descriptor || !("value" in descriptor)) return descriptor;
3753
+ return { ...descriptor, value: read() };
3754
+ }
2285
3755
  });
3756
+ return view;
2286
3757
  }
2287
- var SESSION_ID_ATTRIBUTE, currentSessionStorage, SessionSpanProcessor;
2288
- var init_session2 = __esm({
2289
- "src/tracing/session.ts"() {
3758
+ var SECRET_KEYS, REDACTED2, MIN_SECRET_LENGTH, SpanSecrets, SPAN_SECRETS, SecretRedactingSpanProcessor;
3759
+ var init_secrets = __esm({
3760
+ "src/tracing/secrets.ts"() {
2290
3761
  "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);
3762
+ SECRET_KEYS = /* @__PURE__ */ new Set([
3763
+ "authorization_token",
3764
+ "authorizationToken"
3765
+ ]);
3766
+ REDACTED2 = "[redacted: holds a credential]";
3767
+ MIN_SECRET_LENGTH = 8;
3768
+ SpanSecrets = class {
3769
+ constructor(keys = SECRET_KEYS) {
3770
+ this.keys = keys;
3771
+ }
3772
+ keys;
3773
+ isSecret(key) {
3774
+ return this.keys.has(key);
3775
+ }
3776
+ drops(attribute) {
3777
+ return this.mentions(attribute);
3778
+ }
3779
+ strip(value) {
3780
+ if (typeof value === "string") return this.stripNested(value);
3781
+ if (Array.isArray(value)) return value.map((item) => this.strip(item));
3782
+ if (value === null || typeof value !== "object") return value;
3783
+ return Object.fromEntries(
3784
+ Object.entries(value).filter(([key]) => !this.isSecret(key)).map(([key, item]) => [key, this.strip(item)])
3785
+ );
3786
+ }
3787
+ scrubAttribute(value) {
3788
+ try {
3789
+ return this.scrubbedValue(value);
3790
+ } catch {
3791
+ return Array.isArray(value) ? [REDACTED2] : REDACTED2;
2298
3792
  }
2299
3793
  }
2300
- onEnd(_span) {
3794
+ scrubbedValue(value) {
3795
+ if (typeof value === "string") return this.scrubbedText(value);
3796
+ if (!Array.isArray(value)) return value;
3797
+ const results = value.map(
3798
+ (item) => typeof item === "string" ? this.cleaned(item) : { text: item, removed: /* @__PURE__ */ new Set() }
3799
+ );
3800
+ const removed = new Set(results.flatMap((r) => [...r.removed]));
3801
+ const scrubbed = results.map((r) => r.text);
3802
+ const withheld = scrubbed.some(
3803
+ (item) => typeof item === "string" && this.carries(item, removed)
3804
+ );
3805
+ return withheld ? [REDACTED2] : scrubbed;
2301
3806
  }
2302
- async shutdown() {
3807
+ scrubAttributes(attributes) {
3808
+ return Object.fromEntries(
3809
+ Object.entries(attributes).filter(([key]) => !this.drops(key)).map(([key, value]) => [key, this.scrubAttribute(value)])
3810
+ );
2303
3811
  }
2304
- async forceFlush() {
3812
+ mentions(text2) {
3813
+ return [...this.keys].some((key) => text2.includes(key));
3814
+ }
3815
+ scrubbedText(text2) {
3816
+ const { text: cleaned, removed } = this.cleaned(text2);
3817
+ return this.carries(cleaned, removed) ? REDACTED2 : cleaned;
3818
+ }
3819
+ cleaned(text2) {
3820
+ if (!this.mentions(text2)) return { text: text2, removed: /* @__PURE__ */ new Set() };
3821
+ const parsed = jsonOrUndefined(text2);
3822
+ if (parsed === void 0) return { text: REDACTED2, removed: /* @__PURE__ */ new Set() };
3823
+ return {
3824
+ text: JSON.stringify(this.strip(parsed)),
3825
+ removed: this.removed(parsed)
3826
+ };
3827
+ }
3828
+ carries(text2, removed) {
3829
+ if (text2 === REDACTED2 || this.mentions(text2)) return true;
3830
+ return [...removed].some(
3831
+ (value) => encodings(value).some((form) => text2.includes(form))
3832
+ );
3833
+ }
3834
+ removed(value) {
3835
+ if (typeof value === "string") {
3836
+ const nested = this.mentions(value) ? jsonOrUndefined(value) : void 0;
3837
+ return nested === void 0 ? /* @__PURE__ */ new Set() : this.removed(nested);
3838
+ }
3839
+ if (Array.isArray(value)) return union(value.map((v) => this.removed(v)));
3840
+ if (value === null || typeof value !== "object") return /* @__PURE__ */ new Set();
3841
+ return union(
3842
+ Object.entries(value).map(
3843
+ ([key, item]) => this.isSecret(key) ? leaves(item) : this.removed(item)
3844
+ )
3845
+ );
3846
+ }
3847
+ stripNested(text2) {
3848
+ if (!this.mentions(text2)) return text2;
3849
+ const parsed = jsonOrUndefined(text2);
3850
+ if (parsed === void 0) return text2;
3851
+ return JSON.stringify(this.strip(parsed));
3852
+ }
3853
+ };
3854
+ SPAN_SECRETS = new SpanSecrets();
3855
+ SecretRedactingSpanProcessor = class {
3856
+ constructor(inner, secrets = SPAN_SECRETS) {
3857
+ this.inner = inner;
3858
+ this.secrets = secrets;
3859
+ }
3860
+ inner;
3861
+ secrets;
3862
+ views = /* @__PURE__ */ new WeakMap();
3863
+ onStart(span, parentContext) {
3864
+ this.inner.onStart(this.viewFor(span), parentContext);
3865
+ }
3866
+ onEnd(span) {
3867
+ const view = this.viewFor(span);
3868
+ try {
3869
+ void [view.attributes, view.events, view.status];
3870
+ } catch (error) {
3871
+ console.warn(
3872
+ `[gatewaysdk.tracing] Dropped span "${span.name}": could not redact it: ${error?.name}`
3873
+ );
3874
+ return;
3875
+ }
3876
+ this.inner.onEnd(view);
3877
+ }
3878
+ viewFor(span) {
3879
+ const known = this.views.get(span);
3880
+ if (known) return known;
3881
+ const view = viewOf(span, {
3882
+ attributes: () => this.scrubbedAttributes(span.attributes),
3883
+ events: () => span.events.map((event) => this.scrubbedEvent(event)),
3884
+ status: () => this.scrubbedStatus(span.status)
3885
+ });
3886
+ this.views.set(span, view);
3887
+ return view;
3888
+ }
3889
+ forceFlush() {
3890
+ return this.inner.forceFlush();
3891
+ }
3892
+ shutdown() {
3893
+ return this.inner.shutdown();
3894
+ }
3895
+ scrubbedAttributes(attributes) {
3896
+ const clean = this.secrets.scrubAttributes(attributes);
3897
+ return sameAttributes(attributes, clean) ? attributes : clean;
3898
+ }
3899
+ scrubbedStatus(status) {
3900
+ if (!status.message) return status;
3901
+ const message = this.secrets.scrubAttribute(status.message);
3902
+ return message === status.message ? status : { ...status, message };
3903
+ }
3904
+ scrubbedEvent(event) {
3905
+ if (!event.attributes) return event;
3906
+ const attributes = this.scrubbedAttributes(event.attributes);
3907
+ if (attributes === event.attributes) return event;
3908
+ return { ...event, attributes };
2305
3909
  }
2306
3910
  };
2307
3911
  }
@@ -2528,7 +4132,7 @@ var require_package = __commonJS({
2528
4132
  "package.json"(exports, module) {
2529
4133
  module.exports = {
2530
4134
  name: "@withgateway/sdk",
2531
- version: "0.2.9",
4135
+ version: "0.3.1",
2532
4136
  description: "Gateway SDK for TypeScript - A/B experiments, tracing, and observability",
2533
4137
  main: "./dist/index.js",
2534
4138
  module: "./dist/index.mjs",
@@ -2728,7 +4332,7 @@ var require_package = __commonJS({
2728
4332
  });
2729
4333
 
2730
4334
  // src/build/index.ts
2731
- import { createHash } from "crypto";
4335
+ import { createHash as createHash2 } from "crypto";
2732
4336
  function canonicalJson(value) {
2733
4337
  if (value === null || typeof value !== "object") {
2734
4338
  return JSON.stringify(value);
@@ -2740,7 +4344,7 @@ function canonicalJson(value) {
2740
4344
  return `{${entries.map(([k, v]) => `${JSON.stringify(k)}:${canonicalJson(v)}`).join(",")}}`;
2741
4345
  }
2742
4346
  function sha256(text2) {
2743
- return `sha256:${createHash("sha256").update(text2).digest("hex")}`;
4347
+ return `sha256:${createHash2("sha256").update(text2).digest("hex")}`;
2744
4348
  }
2745
4349
  function getRegisteredTools() {
2746
4350
  return [...registeredTools.values()].sort(
@@ -2937,10 +4541,6 @@ __export(init_exports, {
2937
4541
  isInitialized: () => isInitialized,
2938
4542
  shutdown: () => shutdown
2939
4543
  });
2940
- function getEnv(key) {
2941
- const value = process.env[key];
2942
- return value ? value : void 0;
2943
- }
2944
4544
  function log(message, ...args) {
2945
4545
  if (state.debug) {
2946
4546
  console.log(`[gatewaysdk.tracing] ${message}`, ...args);
@@ -2950,10 +4550,10 @@ function warn(message, ...args) {
2950
4550
  console.warn(`[gatewaysdk.tracing] ${message}`, ...args);
2951
4551
  }
2952
4552
  function buildProvider(config, logFn) {
2953
- const host = config.host ?? getEnv(ENV_VARS.HOST);
2954
- const publicKey = config.publicKey ?? getEnv(ENV_VARS.PUBLIC_KEY);
2955
- const secretKey = config.secretKey ?? getEnv(ENV_VARS.SECRET_KEY);
2956
- const endpoint = config.endpoint ?? getEnv(ENV_VARS.ENDPOINT) ?? (host ? `${host.replace(/\/$/, "")}${DEFAULT_OTLP_PATH}` : void 0);
4553
+ const host = config.host ?? getEnv(GATEWAY_ENV.HOST);
4554
+ const publicKey = config.publicKey ?? getEnv(GATEWAY_ENV.PUBLIC_KEY);
4555
+ const secretKey = config.secretKey ?? getEnv(GATEWAY_ENV.SECRET_KEY);
4556
+ const endpoint = config.endpoint ?? getEnv(GATEWAY_ENV.ENDPOINT) ?? (host ? `${host.replace(/\/$/, "")}${DEFAULT_OTLP_PATH}` : void 0);
2957
4557
  const missing = [];
2958
4558
  if (!host) missing.push("host (or GATEWAY_HOST env var)");
2959
4559
  if (!publicKey) missing.push("publicKey (or GATEWAY_PUBLIC_KEY env var)");
@@ -2990,9 +4590,7 @@ function buildProvider(config, logFn) {
2990
4590
  ATTR_SERVICE_NAME = "service.name";
2991
4591
  }
2992
4592
  } catch {
2993
- throw new Error(
2994
- "OpenTelemetry packages not found. Install them with:\nnpm install @opentelemetry/sdk-trace-node @opentelemetry/sdk-trace-base @opentelemetry/exporter-trace-otlp-http @opentelemetry/resources"
2995
- );
4593
+ throw new OpenTelemetryMissing();
2996
4594
  }
2997
4595
  const resourceAttrs = {
2998
4596
  [ATTR_SERVICE_NAME]: config.serviceName ?? "gatewaysdk-tracing"
@@ -3048,7 +4646,7 @@ function buildProvider(config, logFn) {
3048
4646
  const spanProcessors = [];
3049
4647
  if (config.customSpanProcessors) {
3050
4648
  for (const sp of config.customSpanProcessors) {
3051
- spanProcessors.push(sp);
4649
+ spanProcessors.push(new SecretRedactingSpanProcessor(sp));
3052
4650
  logFn(
3053
4651
  "Added custom span processor: %s",
3054
4652
  sp.constructor?.name ?? "unknown"
@@ -3067,7 +4665,11 @@ function buildProvider(config, logFn) {
3067
4665
  if (config.batch?.maxExportBatchSize) {
3068
4666
  batchConfig.maxExportBatchSize = config.batch.maxExportBatchSize;
3069
4667
  }
3070
- spanProcessors.push(new BatchSpanProcessor(exporter, batchConfig));
4668
+ spanProcessors.push(
4669
+ new SecretRedactingSpanProcessor(
4670
+ new BatchSpanProcessor(exporter, batchConfig)
4671
+ )
4672
+ );
3071
4673
  let provider = new NodeTracerProvider({
3072
4674
  resource: createResource(resourceAttrs)
3073
4675
  });
@@ -3194,26 +4796,17 @@ async function shutdown() {
3194
4796
  function isInitialized() {
3195
4797
  return state.initialized;
3196
4798
  }
3197
- function isGatewayConfigured() {
3198
- const host = getEnv(ENV_VARS.HOST);
3199
- const publicKey = getEnv(ENV_VARS.PUBLIC_KEY);
3200
- const secretKey = getEnv(ENV_VARS.SECRET_KEY);
3201
- return !!(host && publicKey && secretKey);
3202
- }
3203
- var ENV_VARS, DEFAULT_OTLP_PATH, state;
4799
+ var DEFAULT_OTLP_PATH, state;
3204
4800
  var init_init = __esm({
3205
4801
  "src/tracing/init.ts"() {
3206
4802
  "use strict";
3207
4803
  init_identity();
3208
- init_session2();
4804
+ init_secrets();
4805
+ init_session();
3209
4806
  init_scores();
3210
4807
  init_build();
3211
- ENV_VARS = {
3212
- HOST: "GATEWAY_HOST",
3213
- PUBLIC_KEY: "GATEWAY_PUBLIC_KEY",
3214
- SECRET_KEY: "GATEWAY_SECRET_KEY",
3215
- ENDPOINT: "GATEWAY_OTLP_ENDPOINT"
3216
- };
4808
+ init_prerequisites();
4809
+ init_prerequisites();
3217
4810
  DEFAULT_OTLP_PATH = "/api/public/otel/v1/traces";
3218
4811
  state = {
3219
4812
  initialized: false,
@@ -3222,6 +4815,45 @@ var init_init = __esm({
3222
4815
  }
3223
4816
  });
3224
4817
 
4818
+ // src/worlds/taskTracing.ts
4819
+ var TaskTracing;
4820
+ var init_taskTracing = __esm({
4821
+ "src/worlds/taskTracing.ts"() {
4822
+ "use strict";
4823
+ init_prerequisites();
4824
+ TaskTracing = class _TaskTracing {
4825
+ constructor(load = () => Promise.resolve().then(() => (init_init(), init_exports))) {
4826
+ this.load = load;
4827
+ }
4828
+ load;
4829
+ static warned = false;
4830
+ async start(requested) {
4831
+ if (!requested || !isGatewayConfigured()) return false;
4832
+ try {
4833
+ (await this.load()).init();
4834
+ return true;
4835
+ } catch (error) {
4836
+ _TaskTracing.warnOnce(error);
4837
+ return false;
4838
+ }
4839
+ }
4840
+ static warnOnce(error) {
4841
+ if (_TaskTracing.warned) return;
4842
+ _TaskTracing.warned = true;
4843
+ console.warn(
4844
+ `[gatewaysdk.tracing] Task runs in this process are not traced. ${_TaskTracing.reason(error)}
4845
+ Pass --no-trace (trace: false) to run untraced without this warning.`
4846
+ );
4847
+ }
4848
+ static reason(error) {
4849
+ if (OpenTelemetryMissing.explains(error))
4850
+ return new OpenTelemetryMissing().message;
4851
+ return error instanceof Error ? error.message : String(error);
4852
+ }
4853
+ };
4854
+ }
4855
+ });
4856
+
3225
4857
  // src/worlds/taskRun.ts
3226
4858
  import { randomBytes } from "crypto";
3227
4859
  import * as fs from "fs";
@@ -3337,18 +4969,7 @@ async function runTask(ref, agent, opts) {
3337
4969
  const started = Date.now();
3338
4970
  try {
3339
4971
  await live.ready();
3340
- let traced = false;
3341
- if (opts.trace !== false) {
3342
- try {
3343
- const { isGatewayConfigured: isGatewayConfigured2, init: init2 } = await Promise.resolve().then(() => (init_init(), init_exports));
3344
- if (isGatewayConfigured2()) {
3345
- init2();
3346
- traced = true;
3347
- }
3348
- } catch {
3349
- traced = false;
3350
- }
3351
- }
4972
+ const traced = await new TaskTracing().start(opts.trace !== false);
3352
4973
  const taskRun = new TaskRun(
3353
4974
  runId,
3354
4975
  live.instruction ?? "",
@@ -3361,7 +4982,7 @@ async function runTask(ref, agent, opts) {
3361
4982
  let extra = {};
3362
4983
  try {
3363
4984
  const invoke = () => agent(taskRun);
3364
- const result = traced ? await (await Promise.resolve().then(() => (init_session2(), session_exports2))).withSession(runId, invoke) : await invoke();
4985
+ const result = traced ? await (await Promise.resolve().then(() => (init_session(), session_exports))).withSession(runId, invoke) : await invoke();
3365
4986
  ({ report, extra } = reportFromResult(result));
3366
4987
  } catch (error) {
3367
4988
  const message = (error instanceof Error ? error.message : String(error)) || "Unknown error";
@@ -3434,8 +5055,9 @@ var init_taskRun = __esm({
3434
5055
  "use strict";
3435
5056
  init_browser();
3436
5057
  init_evals();
3437
- init_session();
5058
+ init_session2();
3438
5059
  init_taskSessions();
5060
+ init_taskTracing();
3439
5061
  TaskRun = class {
3440
5062
  constructor(runId, instruction, model, sessions, manifest) {
3441
5063
  this.runId = runId;
@@ -3639,6 +5261,52 @@ var init_setRun = __esm({
3639
5261
  }
3640
5262
  });
3641
5263
 
5264
+ // src/worlds/requestLog.ts
5265
+ var WorldRequestLog;
5266
+ var init_requestLog = __esm({
5267
+ "src/worlds/requestLog.ts"() {
5268
+ "use strict";
5269
+ WorldRequestLog = class _WorldRequestLog {
5270
+ constructor(requests) {
5271
+ this.requests = requests;
5272
+ }
5273
+ requests;
5274
+ static async read(session) {
5275
+ const state2 = await session.state();
5276
+ const calls = state2?.calls;
5277
+ if (!Array.isArray(calls)) return null;
5278
+ return new _WorldRequestLog(calls.filter((c) => typeof c === "object" && c !== null));
5279
+ }
5280
+ /** How many older requests the world no longer keeps (its log is bounded): the gap
5281
+ * before the first entry it still holds. */
5282
+ get dropped() {
5283
+ const first = Number(this.requests[0]?.seq) || 1;
5284
+ return Math.max(0, first - 1);
5285
+ }
5286
+ /** Each request in the shape of a ledger line, `kind: "request"`, so one JSONL
5287
+ * file holds both. */
5288
+ asCalls() {
5289
+ return this.requests.map((r) => ({
5290
+ seq: Number(r.seq) || 0,
5291
+ kind: "request",
5292
+ tool: r.operation ?? null,
5293
+ args: {
5294
+ method: r.method ?? null,
5295
+ path: r.path ?? null,
5296
+ args: r.args ?? null,
5297
+ query: r.query ?? null,
5298
+ body: r.body ?? null,
5299
+ via: r.via ?? null
5300
+ },
5301
+ result: { status: r.status ?? null, rows: r.rows ?? null, found: r.found ?? null },
5302
+ error: null,
5303
+ completedAt: r.at ?? null
5304
+ }));
5305
+ }
5306
+ };
5307
+ }
5308
+ });
5309
+
3642
5310
  // src/worlds/checkoutTarget.ts
3643
5311
  import * as fs2 from "fs";
3644
5312
  import * as path2 from "path";
@@ -3743,7 +5411,7 @@ var init_checkoutTarget = __esm({
3743
5411
  });
3744
5412
 
3745
5413
  // src/worlds/worldDir.ts
3746
- import { createHash as createHash2 } from "crypto";
5414
+ import { createHash as createHash3 } from "crypto";
3747
5415
  import * as fs3 from "fs";
3748
5416
  import * as path3 from "path";
3749
5417
  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 +5521,7 @@ var init_worldDir = __esm({
3853
5521
  * sorted order: the version's identity, byte-compatible with
3854
5522
  * `_archive.compute_content_hash` and Prime Intellect. */
3855
5523
  get contentHash() {
3856
- const hasher = createHash2("sha256");
5524
+ const hasher = createHash3("sha256");
3857
5525
  for (const rel of this.archivePaths) {
3858
5526
  hasher.update(Buffer.from(`file:${rel}`, "utf-8"));
3859
5527
  hasher.update(fs3.readFileSync(path3.join(this.dir, rel)));
@@ -4049,7 +5717,7 @@ __export(hub_exports, {
4049
5717
  snapshotTreeHashes: () => snapshotTreeHashes,
4050
5718
  writeLocalMeta: () => writeLocalMeta
4051
5719
  });
4052
- import { createHash as createHash3 } from "crypto";
5720
+ import { createHash as createHash4 } from "crypto";
4053
5721
  import { gzipSync } from "zlib";
4054
5722
  import * as fs5 from "fs";
4055
5723
  import * as path5 from "path";
@@ -4161,7 +5829,7 @@ function writeLocalMeta(dir, meta) {
4161
5829
  function snapshotTreeHashes(dir) {
4162
5830
  const out = {};
4163
5831
  for (const relPath of collectArchiveRelPaths(dir)) {
4164
- out[relPath] = createHash3("sha256").update(fs5.readFileSync(path5.join(dir, relPath))).digest("hex");
5832
+ out[relPath] = createHash4("sha256").update(fs5.readFileSync(path5.join(dir, relPath))).digest("hex");
4165
5833
  }
4166
5834
  return out;
4167
5835
  }
@@ -4207,7 +5875,7 @@ function buildFileManifest(dir) {
4207
5875
  path: relPath,
4208
5876
  isDirectory: false,
4209
5877
  size: payload.length,
4210
- sha256: createHash3("sha256").update(payload).digest("hex")
5878
+ sha256: createHash4("sha256").update(payload).digest("hex")
4211
5879
  };
4212
5880
  });
4213
5881
  }
@@ -4432,7 +6100,7 @@ var init_hub = __esm({
4432
6100
  tracked;
4433
6101
  declared;
4434
6102
  };
4435
- sha256b64 = (data) => createHash3("sha256").update(data).digest("base64");
6103
+ sha256b64 = (data) => createHash4("sha256").update(data).digest("base64");
4436
6104
  DetachedPushError = class extends Error {
4437
6105
  constructor(dir, tag) {
4438
6106
  super(
@@ -5059,7 +6727,7 @@ var init_json = __esm({
5059
6727
  });
5060
6728
 
5061
6729
  // src/worlds/transforms.ts
5062
- import { createHash as createHash4 } from "crypto";
6730
+ import { createHash as createHash5 } from "crypto";
5063
6731
  function parseTransform(name) {
5064
6732
  const simple = Object.prototype.hasOwnProperty.call(SIMPLE, name) ? SIMPLE[name] : void 0;
5065
6733
  if (simple) return simple;
@@ -5097,7 +6765,7 @@ var init_transforms = __esm({
5097
6765
  return at === -1 ? "" : value.slice(at + 1).toLowerCase();
5098
6766
  };
5099
6767
  stripPrefix = (prefix) => (value) => value.startsWith(prefix) ? value.slice(prefix.length) : value;
5100
- hex = (algorithm, value) => createHash4(algorithm).update(value, "utf8").digest("hex");
6768
+ hex = (algorithm, value) => createHash5(algorithm).update(value, "utf8").digest("hex");
5101
6769
  SIMPLE = {
5102
6770
  lower: (value) => value.toLowerCase(),
5103
6771
  upper: (value) => value.toUpperCase(),
@@ -5121,7 +6789,7 @@ var init_transforms = __esm({
5121
6789
  });
5122
6790
 
5123
6791
  // src/worlds/redaction.ts
5124
- import { createHash as createHash5 } from "crypto";
6792
+ import { createHash as createHash6 } from "crypto";
5125
6793
  function pyText(value) {
5126
6794
  if (typeof value === "string") return value;
5127
6795
  if (Number.isInteger(value)) return String(value);
@@ -5130,7 +6798,7 @@ function pyText(value) {
5130
6798
  return pyFloatRepr(value);
5131
6799
  }
5132
6800
  function hashForm(slug, plaintext) {
5133
- return "sha256:" + createHash5("sha256").update(`${slug}:${pyText(plaintext)}`, "utf8").digest("hex");
6801
+ return "sha256:" + createHash6("sha256").update(`${slug}:${pyText(plaintext)}`, "utf8").digest("hex");
5134
6802
  }
5135
6803
  function preserveForm(slug, plaintext) {
5136
6804
  const kind = typeof plaintext === "string" ? "str" : isInt(plaintext) ? "int" : "float";
@@ -5139,12 +6807,12 @@ function preserveForm(slug, plaintext) {
5139
6807
  }
5140
6808
  function shapeText(slug, text2, kind) {
5141
6809
  const seed = Buffer.from(`${slug}:${text2}`, "utf8");
5142
- let digest = createHash5("sha256").update(seed).digest();
6810
+ let digest = createHash6("sha256").update(seed).digest();
5143
6811
  let cursor = 0;
5144
6812
  const out = [];
5145
6813
  for (const char of text2) {
5146
6814
  if (cursor === digest.length) {
5147
- digest = createHash5("sha256").update(Buffer.concat([digest, seed])).digest();
6815
+ digest = createHash6("sha256").update(Buffer.concat([digest, seed])).digest();
5148
6816
  cursor = 0;
5149
6817
  }
5150
6818
  const byte = digest[cursor];
@@ -5472,13 +7140,14 @@ async function localBridge(request, local, opts = {}) {
5472
7140
  child.stdin.end(input);
5473
7141
  });
5474
7142
  }
5475
- var MIN_PYTHON, DIAGNOSTIC_TAIL, BRIDGE_BOOTSTRAP, pythonCache, pythonProbes, PYTHON_CANDIDATES, UV_FIND;
7143
+ var MIN_PYTHON, MIN_PYTHON_LABEL, DIAGNOSTIC_TAIL, BRIDGE_BOOTSTRAP, pythonCache, pythonProbes, PYTHON_CANDIDATES, UV_FIND;
5476
7144
  var init_local = __esm({
5477
7145
  "src/cli/runtime/local.ts"() {
5478
7146
  "use strict";
5479
7147
  init_router();
5480
7148
  init_config();
5481
7149
  MIN_PYTHON = [3, 12];
7150
+ MIN_PYTHON_LABEL = MIN_PYTHON.join(".");
5482
7151
  DIAGNOSTIC_TAIL = 600;
5483
7152
  BRIDGE_BOOTSTRAP = `import sys,runpy,types,os
5484
7153
  root=sys.argv[1]
@@ -6043,7 +7712,7 @@ if (fn) {
6043
7712
  });
6044
7713
 
6045
7714
  // src/cli/platform/worldData/batches.ts
6046
- import { createHash as createHash6 } from "crypto";
7715
+ import { createHash as createHash7 } from "crypto";
6047
7716
  import * as fs11 from "fs";
6048
7717
  function isSettled(status) {
6049
7718
  if (!TERMINAL_STATES.has(status.state)) return false;
@@ -6054,7 +7723,7 @@ function uploadHeadersFor(gz) {
6054
7723
  return {
6055
7724
  "content-type": "application/gzip",
6056
7725
  "content-length": String(gz.length),
6057
- "x-amz-checksum-sha256": createHash6("sha256").update(gz).digest("base64")
7726
+ "x-amz-checksum-sha256": createHash7("sha256").update(gz).digest("base64")
6058
7727
  };
6059
7728
  }
6060
7729
  async function forEachLimited(items, limit, fn) {
@@ -6257,7 +7926,7 @@ var init_batches = __esm({
6257
7926
  });
6258
7927
 
6259
7928
  // src/cli/platform/worldData/chunker.ts
6260
- import { createHash as createHash7 } from "crypto";
7929
+ import { createHash as createHash8 } from "crypto";
6261
7930
  import { deflateRawSync } from "zlib";
6262
7931
  function chunkLine(row, declared) {
6263
7932
  if (declared !== null) return dumps(row.row) + "\n";
@@ -6298,12 +7967,12 @@ function finishChunk(ordinal, raw, rows, entity, firstRow = 0) {
6298
7967
  const gz = gzipDeterministic(raw, { name: chunkName(ordinal) });
6299
7968
  return {
6300
7969
  ordinal,
6301
- digest: createHash7("sha256").update(gz).digest("hex"),
7970
+ digest: createHash8("sha256").update(gz).digest("hex"),
6302
7971
  bytes: gz.length,
6303
7972
  rows,
6304
7973
  entity,
6305
7974
  rawBytes: raw.length,
6306
- contentSha256: createHash7("sha256").update(raw).digest("hex"),
7975
+ contentSha256: createHash8("sha256").update(raw).digest("hex"),
6307
7976
  firstRow,
6308
7977
  gz
6309
7978
  };
@@ -6640,7 +8309,7 @@ var init_ingest = __esm({
6640
8309
  });
6641
8310
 
6642
8311
  // src/worlds/editSessions.ts
6643
- var WORLDS, WorldEditClient;
8312
+ var WORLDS, WorldEditClient, TASK_EDITS, TaskEditClient;
6644
8313
  var init_editSessions = __esm({
6645
8314
  "src/worlds/editSessions.ts"() {
6646
8315
  "use strict";
@@ -6672,6 +8341,22 @@ var init_editSessions = __esm({
6672
8341
  return apiRequest(this.options, "POST", `${WORLDS}/${encodeURIComponent(slug)}/edits/rollback`, input);
6673
8342
  }
6674
8343
  };
8344
+ TASK_EDITS = "/api/public/world-task-edits";
8345
+ TaskEditClient = class {
8346
+ constructor(options = {}) {
8347
+ this.options = options;
8348
+ }
8349
+ options;
8350
+ status(task) {
8351
+ return apiRequest(this.options, "POST", `${TASK_EDITS}/status`, { task });
8352
+ }
8353
+ close(task, input = {}) {
8354
+ return apiRequest(this.options, "POST", `${TASK_EDITS}/close`, { task, ...input });
8355
+ }
8356
+ rollback(task, input) {
8357
+ return apiRequest(this.options, "POST", `${TASK_EDITS}/rollback`, { task, ...input });
8358
+ }
8359
+ };
6675
8360
  }
6676
8361
  });
6677
8362
 
@@ -6767,6 +8452,10 @@ var init_dryRun = __esm({
6767
8452
  // src/worlds/index.ts
6768
8453
  var worlds_exports = {};
6769
8454
  __export(worlds_exports, {
8455
+ ACTION_NAMES: () => ACTION_NAMES,
8456
+ ActionTracer: () => ActionTracer,
8457
+ AnthropicComputer: () => AnthropicComputer,
8458
+ AnthropicComputer20251124: () => AnthropicComputer20251124,
6770
8459
  ApiError: () => ApiError,
6771
8460
  BROWSER_GONE_PATTERNS: () => BROWSER_GONE_PATTERNS,
6772
8461
  BROWSER_TIERS: () => BROWSER_TIERS,
@@ -6778,11 +8467,13 @@ __export(worlds_exports, {
6778
8467
  CALL_BODY_LIMIT_LABEL: () => CALL_BODY_LIMIT_LABEL,
6779
8468
  COMPUTER_USE_SPECS: () => COMPUTER_USE_SPECS,
6780
8469
  CheckoutProvenance: () => CheckoutProvenance,
8470
+ ComputerAction: () => ComputerAction,
6781
8471
  DEFAULT_BRANCH: () => DEFAULT_BRANCH,
6782
8472
  DEFAULT_VIEWPORT: () => DEFAULT_VIEWPORT,
6783
8473
  DRY_RUN_AGENT: () => DRY_RUN_AGENT,
6784
8474
  DRY_RUN_KIND: () => DRY_RUN_KIND,
6785
8475
  DetachedPushError: () => DetachedPushError,
8476
+ Display: () => Display,
6786
8477
  DryRunOutcome: () => DryRunOutcome,
6787
8478
  EVENT_BATCH_SIZE: () => EVENT_BATCH_SIZE,
6788
8479
  EVENT_FLUSH_INTERVAL_MS: () => EVENT_FLUSH_INTERVAL_MS,
@@ -6792,19 +8483,30 @@ __export(worlds_exports, {
6792
8483
  GatewayEvalsClient: () => GatewayEvalsClient,
6793
8484
  HostedDryRunClient: () => HostedDryRunClient,
6794
8485
  IDLE_WARNING_MINUTES: () => IDLE_WARNING_MINUTES,
8486
+ KEY_NAMES: () => KEY_NAMES,
8487
+ KeyChord: () => KeyChord,
8488
+ NOT_EXECUTED: () => NOT_EXECUTED,
6795
8489
  NO_GRADER_REASON: () => NO_GRADER_REASON,
8490
+ NativeComputer: () => NativeComputer,
8491
+ OpenAIComputer: () => OpenAIComputer,
8492
+ OpenAIPreviewComputer: () => OpenAIPreviewComputer,
6796
8493
  PLATFORM_TIMEOUT_DEFAULT_MS: () => PLATFORM_TIMEOUT_DEFAULT_MS,
6797
8494
  PLATFORM_TIMEOUT_ENV: () => PLATFORM_TIMEOUT_ENV,
8495
+ PendingSafetyChecks: () => PendingSafetyChecks,
6798
8496
  PlatformTransport: () => PlatformTransport,
6799
8497
  PushSlugConflict: () => PushSlugConflict,
6800
8498
  RECOVER_BUDGET_MS: () => RECOVER_BUDGET_MS,
6801
8499
  SANDBOX_REQUEST_TIMEOUT_MS: () => SANDBOX_REQUEST_TIMEOUT_MS,
8500
+ SECRET_KEY: () => SECRET_KEY,
6802
8501
  SESSION_STATES: () => SESSION_STATES,
8502
+ SPAN_PREFIX: () => SPAN_PREFIX,
6803
8503
  STATUS_WAIT_CAP_SECONDS: () => STATUS_WAIT_CAP_SECONDS,
6804
8504
  STRIP_PREFIX: () => STRIP_PREFIX,
6805
8505
  SURFACE_KINDS: () => SURFACE_KINDS,
8506
+ Screen: () => Screen,
6806
8507
  SecretScrubber: () => SecretScrubber,
6807
8508
  TRANSFORMS: () => TRANSFORMS,
8509
+ TaskEditClient: () => TaskEditClient,
6808
8510
  TaskRun: () => TaskRun,
6809
8511
  TaskSessions: () => TaskSessions,
6810
8512
  TransportCause: () => TransportCause,
@@ -6814,6 +8516,7 @@ __export(worlds_exports, {
6814
8516
  WorldBrowser: () => WorldBrowser,
6815
8517
  WorldCallTooLarge: () => WorldCallTooLarge,
6816
8518
  WorldEditClient: () => WorldEditClient,
8519
+ WorldRequestLog: () => WorldRequestLog,
6817
8520
  WorldSandboxClient: () => WorldSandboxClient,
6818
8521
  WorldSession: () => WorldSession,
6819
8522
  WorldSessionCallError: () => WorldSessionCallError,
@@ -6877,6 +8580,7 @@ __export(worlds_exports, {
6877
8580
  parseTransform: () => parseTransform,
6878
8581
  parseWorldTaskRefs: () => parseWorldTaskRefs,
6879
8582
  platformTimeoutMs: () => platformTimeoutMs,
8583
+ playwrightKey: () => playwrightKey,
6880
8584
  preserveForm: () => preserveForm,
6881
8585
  propose: () => propose,
6882
8586
  pull: () => pull,
@@ -6886,6 +8590,7 @@ __export(worlds_exports, {
6886
8590
  pyText: () => pyText,
6887
8591
  queryRows: () => queryRows,
6888
8592
  queryRowsSearch: () => queryRowsSearch,
8593
+ readField: () => readField,
6889
8594
  readLocalMeta: () => readLocalMeta,
6890
8595
  readToolCallRecords: () => readToolCallRecords,
6891
8596
  rebaseConflicts: () => rebaseConflicts,
@@ -6905,6 +8610,7 @@ __export(worlds_exports, {
6905
8610
  shapeText: () => shapeText,
6906
8611
  snapshotTreeHashes: () => snapshotTreeHashes,
6907
8612
  storedForms: () => storedForms,
8613
+ surfaceDescriptor: () => surfaceDescriptor,
6908
8614
  surfaceKinds: () => surfaceKinds,
6909
8615
  taskLabel: () => taskLabel,
6910
8616
  toolCallRecordsIn: () => toolCallRecordsIn,
@@ -7134,7 +8840,7 @@ var init_worlds = __esm({
7134
8840
  "src/worlds/index.ts"() {
7135
8841
  init_transport();
7136
8842
  init_transport();
7137
- init_session();
8843
+ init_session2();
7138
8844
  init_sessionList();
7139
8845
  init_sessionContract();
7140
8846
  init_taskRef();
@@ -7145,7 +8851,10 @@ var init_worlds = __esm({
7145
8851
  init_checkoutProvenance();
7146
8852
  init_evals();
7147
8853
  init_browser();
8854
+ init_surfaceDescriptor();
8855
+ init_requestLog();
7148
8856
  init_browserReconnect();
8857
+ init_nativeComputer();
7149
8858
  init_hub();
7150
8859
  init_validate();
7151
8860
  init_describe();
@@ -7212,7 +8921,7 @@ var init_worlds = __esm({
7212
8921
  * worlds/session.ts.
7213
8922
  */
7214
8923
  async open(task, opts = {}) {
7215
- const { openSession: openSession2 } = await Promise.resolve().then(() => (init_session(), session_exports));
8924
+ const { openSession: openSession2 } = await Promise.resolve().then(() => (init_session2(), session_exports2));
7216
8925
  return openSession2(this.slug, {
7217
8926
  task,
7218
8927
  versionId: this.version.versionId,
@@ -7246,6 +8955,10 @@ var init_worlds = __esm({
7246
8955
  });
7247
8956
  init_worlds();
7248
8957
  export {
8958
+ ACTION_NAMES,
8959
+ ActionTracer,
8960
+ AnthropicComputer,
8961
+ AnthropicComputer20251124,
7249
8962
  ApiError,
7250
8963
  BROWSER_GONE_PATTERNS,
7251
8964
  BROWSER_TIERS,
@@ -7257,11 +8970,13 @@ export {
7257
8970
  CALL_BODY_LIMIT_LABEL,
7258
8971
  COMPUTER_USE_SPECS,
7259
8972
  CheckoutProvenance,
8973
+ ComputerAction,
7260
8974
  DEFAULT_BRANCH,
7261
8975
  DEFAULT_VIEWPORT,
7262
8976
  DRY_RUN_AGENT,
7263
8977
  DRY_RUN_KIND,
7264
8978
  DetachedPushError,
8979
+ Display,
7265
8980
  DryRunOutcome,
7266
8981
  EVENT_BATCH_SIZE,
7267
8982
  EVENT_FLUSH_INTERVAL_MS,
@@ -7271,19 +8986,30 @@ export {
7271
8986
  GatewayEvalsClient,
7272
8987
  HostedDryRunClient,
7273
8988
  IDLE_WARNING_MINUTES,
8989
+ KEY_NAMES,
8990
+ KeyChord,
8991
+ NOT_EXECUTED,
7274
8992
  NO_GRADER_REASON,
8993
+ NativeComputer,
8994
+ OpenAIComputer,
8995
+ OpenAIPreviewComputer,
7275
8996
  PLATFORM_TIMEOUT_DEFAULT_MS,
7276
8997
  PLATFORM_TIMEOUT_ENV,
8998
+ PendingSafetyChecks,
7277
8999
  PlatformTransport,
7278
9000
  PushSlugConflict,
7279
9001
  RECOVER_BUDGET_MS,
7280
9002
  SANDBOX_REQUEST_TIMEOUT_MS,
9003
+ SECRET_KEY,
7281
9004
  SESSION_STATES,
9005
+ SPAN_PREFIX,
7282
9006
  STATUS_WAIT_CAP_SECONDS,
7283
9007
  STRIP_PREFIX,
7284
9008
  SURFACE_KINDS,
9009
+ Screen,
7285
9010
  SecretScrubber,
7286
9011
  TRANSFORMS,
9012
+ TaskEditClient,
7287
9013
  TaskRun,
7288
9014
  TaskSessions,
7289
9015
  TransportCause,
@@ -7293,6 +9019,7 @@ export {
7293
9019
  WorldBrowser,
7294
9020
  WorldCallTooLarge,
7295
9021
  WorldEditClient,
9022
+ WorldRequestLog,
7296
9023
  WorldSandboxClient,
7297
9024
  WorldSession,
7298
9025
  WorldSessionCallError,
@@ -7356,6 +9083,7 @@ export {
7356
9083
  parseTransform,
7357
9084
  parseWorldTaskRefs,
7358
9085
  platformTimeoutMs,
9086
+ playwrightKey,
7359
9087
  preserveForm,
7360
9088
  propose,
7361
9089
  pull,
@@ -7365,6 +9093,7 @@ export {
7365
9093
  pyText,
7366
9094
  queryRows,
7367
9095
  queryRowsSearch,
9096
+ readField,
7368
9097
  readLocalMeta,
7369
9098
  readToolCallRecords,
7370
9099
  rebaseConflicts,
@@ -7384,6 +9113,7 @@ export {
7384
9113
  shapeText,
7385
9114
  snapshotTreeHashes,
7386
9115
  storedForms,
9116
+ surfaceDescriptor,
7387
9117
  surfaceKinds,
7388
9118
  taskLabel,
7389
9119
  toolCallRecordsIn,