@withgateway/sdk 0.2.8 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. package/README.md +24 -8
  2. package/dist/cli.js +2695 -657
  3. package/dist/cli.js.map +1 -1
  4. package/dist/cli.mjs +2675 -637
  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 +1443 -36
  9. package/dist/files/index.js.map +1 -1
  10. package/dist/files/index.mjs +1441 -28
  11. package/dist/files/index.mjs.map +1 -1
  12. package/dist/{index-Cz8Q6Keo.d.mts → index-D6oi1TWE.d.mts} +93 -34
  13. package/dist/{index-BO2SNSgy.d.ts → index-DAb-FCMg.d.ts} +93 -34
  14. package/dist/index.d.mts +4 -3
  15. package/dist/index.d.ts +4 -3
  16. package/dist/index.js +1986 -235
  17. package/dist/index.js.map +1 -1
  18. package/dist/index.mjs +1941 -218
  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 +1440 -33
  25. package/dist/traces/index.js.map +1 -1
  26. package/dist/traces/index.mjs +1438 -25
  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 +512 -11
  31. package/dist/tracing/index.js.map +1 -1
  32. package/dist/tracing/index.mjs +501 -10
  33. package/dist/tracing/index.mjs.map +1 -1
  34. package/dist/worlds/index.d.mts +614 -25
  35. package/dist/worlds/index.d.ts +614 -25
  36. package/dist/worlds/index.js +1923 -214
  37. package/dist/worlds/index.js.map +1 -1
  38. package/dist/worlds/index.mjs +1910 -201
  39. package/dist/worlds/index.mjs.map +1 -1
  40. package/package.json +1 -1
  41. package/runtime/gatewaysdk/environment/_toml.py +3 -10
  42. package/runtime/gatewaysdk/environment/schema/api.py +38 -56
  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/runtime.py +9 -9
  47. package/runtime/gatewaysdk/environment/schema/skills/benchmarks-getting-started/SKILL.md +3 -3
  48. package/runtime/gatewaysdk/environment/schema/skills/connector-schema-authoring/SKILL.md +1 -1
  49. package/runtime/gatewaysdk/environment/schema/skills/worlds-getting-started/SKILL.md +18 -18
  50. package/runtime/gatewaysdk/environment/schema/skills/worlds-getting-started/references/cli-mcp-map.md +4 -2
  51. package/runtime/gatewaysdk/environment/schema/skills/worlds-getting-started/references/gotchas.md +5 -1
  52. package/runtime/gatewaysdk/environment/schema/skills/worlds-getting-started/references/new-world-sandbox.md +5 -3
  53. package/runtime/gatewaysdk/environment/schema/store.py +15 -6
  54. package/runtime/gatewaysdk/environment/schema/tasks.py +25 -1
  55. package/skills/benchmarks-getting-started/SKILL.md +3 -3
  56. package/skills/connector-schema-authoring/SKILL.md +1 -1
  57. package/skills/connector-schema-authoring/world-schema.md +1 -1
  58. package/skills/worlds-getting-started/SKILL.md +18 -18
  59. package/skills/worlds-getting-started/references/cli-mcp-map.md +4 -2
  60. package/skills/worlds-getting-started/references/gotchas.md +5 -1
  61. package/skills/worlds-getting-started/references/new-world-sandbox.md +5 -3
@@ -28,6 +28,115 @@ var __export = (target, all) => {
28
28
  __defProp(target, name, { get: all[name], enumerable: true });
29
29
  };
30
30
 
31
+ // src/worlds/transport.ts
32
+ function platformTimeoutMs(env = process.env) {
33
+ const raw = env[PLATFORM_TIMEOUT_ENV];
34
+ if (raw === void 0 || raw === "") return PLATFORM_TIMEOUT_DEFAULT_MS;
35
+ const value = Number(raw);
36
+ if (Number.isInteger(value) && value > 0) return value;
37
+ throw new Error(`${PLATFORM_TIMEOUT_ENV} must be a positive whole number of milliseconds, not \`${raw}\`.`);
38
+ }
39
+ var PLATFORM_TIMEOUT_ENV, PLATFORM_TIMEOUT_DEFAULT_MS, CHECK_HOST, RETRY, CAUSES, UNKNOWN_CAUSE, TransportCause, UnreachableError, PlatformTransport;
40
+ var init_transport = __esm({
41
+ "src/worlds/transport.ts"() {
42
+ "use strict";
43
+ PLATFORM_TIMEOUT_ENV = "GATEWAY_TIMEOUT_MS";
44
+ PLATFORM_TIMEOUT_DEFAULT_MS = 12e4;
45
+ CHECK_HOST = "Check GATEWAY_HOST (or --host) points at a running platform, then retry.";
46
+ RETRY = "Retry; if it repeats, check the network between here and the platform.";
47
+ CAUSES = {
48
+ ECONNREFUSED: { reason: "connection refused", next: CHECK_HOST },
49
+ ENOTFOUND: { reason: "DNS lookup failed", next: CHECK_HOST },
50
+ EAI_AGAIN: { reason: "DNS lookup failed", next: CHECK_HOST },
51
+ ETIMEDOUT: { reason: "connect timed out", next: CHECK_HOST },
52
+ UND_ERR_CONNECT_TIMEOUT: { reason: "connect timed out", next: CHECK_HOST },
53
+ EHOSTUNREACH: { reason: "host unreachable", next: CHECK_HOST },
54
+ ENETUNREACH: { reason: "network unreachable", next: RETRY },
55
+ ECONNRESET: { reason: "connection dropped", next: RETRY },
56
+ UND_ERR_SOCKET: { reason: "connection dropped", next: RETRY },
57
+ EPIPE: { reason: "connection dropped", next: RETRY }
58
+ };
59
+ UNKNOWN_CAUSE = { reason: "network error", next: CHECK_HOST };
60
+ TransportCause = class _TransportCause {
61
+ constructor(reason, detail, next) {
62
+ this.reason = reason;
63
+ this.detail = detail;
64
+ this.next = next;
65
+ }
66
+ reason;
67
+ detail;
68
+ next;
69
+ static timeout(timeoutMs) {
70
+ return new _TransportCause(
71
+ `timed out after ${timeoutMs / 1e3}s`,
72
+ null,
73
+ `Retry; if the platform is slow, raise ${PLATFORM_TIMEOUT_ENV} (milliseconds per request).`
74
+ );
75
+ }
76
+ static of(error) {
77
+ const cause = error instanceof Error && error.cause instanceof Error ? error.cause : void 0;
78
+ const code = cause && "code" in cause && typeof cause.code === "string" ? cause.code : null;
79
+ const message = cause?.message ?? (error instanceof Error ? error.message : String(error));
80
+ const known = code && CAUSES[code] || UNKNOWN_CAUSE;
81
+ return new _TransportCause(known.reason, code ? `${code}: ${message}` : message, known.next);
82
+ }
83
+ describe() {
84
+ return this.detail === null ? this.reason : `${this.reason} (${this.detail})`;
85
+ }
86
+ };
87
+ UnreachableError = class extends Error {
88
+ constructor(host, method, route, failure) {
89
+ super(`${method} ${route}: no answer from ${host}: ${failure.describe()}. ${failure.next}`);
90
+ this.host = host;
91
+ this.method = method;
92
+ this.route = route;
93
+ this.failure = failure;
94
+ this.name = "UnreachableError";
95
+ }
96
+ host;
97
+ method;
98
+ route;
99
+ failure;
100
+ };
101
+ PlatformTransport = class {
102
+ constructor(endpoint, timeoutMs = platformTimeoutMs()) {
103
+ this.endpoint = endpoint;
104
+ this.timeoutMs = timeoutMs;
105
+ }
106
+ endpoint;
107
+ timeoutMs;
108
+ /** A request that legitimately takes longer (a sandbox exec, a world create) waits its own budget; every other one waits the default. */
109
+ budget(ownMs) {
110
+ return Math.max(ownMs ?? 0, this.timeoutMs);
111
+ }
112
+ async send(method, route, body, opts = {}) {
113
+ const timeoutMs = this.budget(opts.timeoutMs);
114
+ const payload = body === void 0 ? {} : { body: JSON.stringify(body) };
115
+ const controller = new AbortController();
116
+ const timer = setTimeout(() => controller.abort(), timeoutMs);
117
+ try {
118
+ const res = await fetch(`${this.endpoint.host}${route}`, {
119
+ method,
120
+ headers: {
121
+ "content-type": "application/json",
122
+ accept: "application/json",
123
+ authorization: "Basic " + Buffer.from(`${this.endpoint.publicKey}:${this.endpoint.secretKey}`).toString("base64")
124
+ },
125
+ ...payload,
126
+ signal: controller.signal
127
+ });
128
+ return { status: res.status, ok: res.ok, text: await res.text() };
129
+ } catch (error) {
130
+ const cause = controller.signal.aborted ? TransportCause.timeout(timeoutMs) : TransportCause.of(error);
131
+ throw new UnreachableError(this.endpoint.host, method, route, cause);
132
+ } finally {
133
+ clearTimeout(timer);
134
+ }
135
+ }
136
+ };
137
+ }
138
+ });
139
+
31
140
  // src/worlds/browserReconnect.ts
32
141
  async function closeConnection(c) {
33
142
  await c.context.close();
@@ -211,7 +320,7 @@ function withoutUiToken(url) {
211
320
  const [beforeHash, hash] = splitHash(url);
212
321
  const q = beforeHash.indexOf("?");
213
322
  if (q < 0) return url;
214
- 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);
215
324
  return beforeHash.slice(0, q) + (kept.length ? `?${kept.join("&")}` : "") + hash;
216
325
  }
217
326
  function splitHash(url) {
@@ -346,7 +455,7 @@ var SURFACE_KINDS, BROWSER_TIERS, DEFAULT_VIEWPORT, SETTLE_TIMEOUT_MS, SETTLE_QU
346
455
  var init_browser = __esm({
347
456
  "src/worlds/browser.ts"() {
348
457
  "use strict";
349
- init_session();
458
+ init_session2();
350
459
  init_browserReconnect();
351
460
  SURFACE_KINDS = ["tools", "api", "ui", "browser"];
352
461
  BROWSER_TIERS = ["standard", "premium"];
@@ -492,6 +601,10 @@ var init_browser = __esm({
492
601
  get agentId() {
493
602
  return this.recorder?.agentId ?? null;
494
603
  }
604
+ /** `text` with this session's credentials (UI token, browser address) removed. */
605
+ scrub(text2) {
606
+ return this.scrubber.scrub(text2);
607
+ }
495
608
  watchNetwork(page) {
496
609
  page.on("request", () => {
497
610
  this.inflight += 1;
@@ -773,8 +886,1271 @@ var init_browser = __esm({
773
886
  signature: "browser_back()",
774
887
  doc: "Go back one page in history."
775
888
  }
776
- ];
777
- 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();
778
2154
  }
779
2155
  });
780
2156
 
@@ -831,6 +2207,75 @@ var init_sessionContract = __esm({
831
2207
  }
832
2208
  });
833
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
+
834
2279
  // src/worlds/taskRef.ts
835
2280
  var isTaskIdRef, isTaskSpec, taskLabel, assertTaskRef;
836
2281
  var init_taskRef = __esm({
@@ -855,8 +2300,8 @@ var init_taskRef = __esm({
855
2300
  });
856
2301
 
857
2302
  // src/worlds/session.ts
858
- var session_exports = {};
859
- __export(session_exports, {
2303
+ var session_exports2 = {};
2304
+ __export(session_exports2, {
860
2305
  WorldSession: () => WorldSession,
861
2306
  WorldSessionCallError: () => WorldSessionCallError,
862
2307
  WorldSessionTimeout: () => WorldSessionTimeout,
@@ -910,7 +2355,7 @@ function schemaFromSignature(spec) {
910
2355
  };
911
2356
  const inside = /\(([\s\S]*)\)\s*$/.exec(spec.signature.trim())?.[1] ?? "";
912
2357
  const properties = {};
913
- const required = [];
2358
+ const required2 = [];
914
2359
  const params = [];
915
2360
  let depth = 0;
916
2361
  let current = "";
@@ -931,7 +2376,7 @@ function schemaFromSignature(spec) {
931
2376
  if (!name) continue;
932
2377
  if (eq === -1) {
933
2378
  properties[name] = { type: "string" };
934
- required.push(name);
2379
+ required2.push(name);
935
2380
  continue;
936
2381
  }
937
2382
  const value = param.slice(eq + 1).trim();
@@ -945,7 +2390,7 @@ function schemaFromSignature(spec) {
945
2390
  function: {
946
2391
  name: modelToolName(spec.name),
947
2392
  description: spec.doc ?? spec.name,
948
- parameters: { type: "object", properties, required }
2393
+ parameters: { type: "object", properties, required: required2 }
949
2394
  }
950
2395
  };
951
2396
  }
@@ -1014,13 +2459,16 @@ async function runSessions(opts) {
1014
2459
  task = taskLabel(taskRef, session.taskInfo);
1015
2460
  await session.ready();
1016
2461
  const toolkit = await session.toolkit();
1017
- await opts.agent({
1018
- session,
1019
- toolkit,
1020
- instruction: session.instruction ?? (isTaskSpec(taskRef) ? taskRef.instruction : task),
1021
- task,
1022
- taskRef
1023
- });
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
+ );
1024
2472
  const graded = await session.grade();
1025
2473
  const result = {
1026
2474
  task,
@@ -1058,12 +2506,14 @@ async function runSessions(opts) {
1058
2506
  };
1059
2507
  }
1060
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;
1061
- var init_session = __esm({
2509
+ var init_session2 = __esm({
1062
2510
  "src/worlds/session.ts"() {
1063
2511
  "use strict";
1064
2512
  init_worlds();
1065
2513
  init_browser();
2514
+ init_nativeComputer();
1066
2515
  init_sessionContract();
2516
+ init_session();
1067
2517
  init_taskRef();
1068
2518
  init_taskRef();
1069
2519
  READY_TIMEOUT_MS = 10 * 6e4;
@@ -1217,6 +2667,12 @@ var init_session = __esm({
1217
2667
  computerUseTools(browser) {
1218
2668
  return computerUseToolkit(browser);
1219
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
+ }
1220
2676
  /** The session's latest platform state (one request, no waiting). */
1221
2677
  async status() {
1222
2678
  const fresh = await apiRequest(
@@ -1451,6 +2907,21 @@ var init_session = __esm({
1451
2907
  { keepWarm: opts.keepWarm ?? false }
1452
2908
  );
1453
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
+ }
1454
2925
  };
1455
2926
  OPEN_SESSION_OPTION_KEYS = /* @__PURE__ */ new Set([
1456
2927
  "task",
@@ -1600,7 +3071,11 @@ function fromResponse(answer, options) {
1600
3071
  const worlds = {};
1601
3072
  for (const [alias, state2] of Object.entries(answer.sessions)) {
1602
3073
  sessions[alias] = new WorldSession(state2.sessionId, state2, options);
1603
- worlds[alias] = { slug: state2.slug, ref: state2.ref };
3074
+ worlds[alias] = {
3075
+ slug: state2.slug,
3076
+ ref: state2.ref,
3077
+ private: state2.private ?? null
3078
+ };
1604
3079
  }
1605
3080
  return new TaskSessions(
1606
3081
  answer.taskId,
@@ -1674,6 +3149,7 @@ async function attachTask(taskId, options = {}) {
1674
3149
  {
1675
3150
  slug: row.slug ?? "",
1676
3151
  ref: null,
3152
+ private: null,
1677
3153
  versionId: row.versionId,
1678
3154
  sessionId: row.sessionId,
1679
3155
  ready: row.ready,
@@ -1703,7 +3179,7 @@ async function attachManifest(manifest, options = {}) {
1703
3179
  Object.fromEntries(
1704
3180
  Object.entries(manifest.sessions).map(([alias, entry]) => [
1705
3181
  alias,
1706
- { slug: entry.slug, ref: entry.ref }
3182
+ { slug: entry.slug, ref: entry.ref, private: entry.private ?? null }
1707
3183
  ])
1708
3184
  )
1709
3185
  );
@@ -1717,12 +3193,13 @@ var init_taskSessions = __esm({
1717
3193
  "use strict";
1718
3194
  init_worlds();
1719
3195
  init_browser();
1720
- init_session();
3196
+ init_session2();
1721
3197
  TASK_SESSIONS = "/api/public/world-task-sessions";
1722
3198
  VERIFIER_REWARD_PREFIX = "x.";
1723
3199
  manifestSession = (s, state2, world) => ({
1724
3200
  slug: world.slug,
1725
3201
  ref: world.ref,
3202
+ private: world.private,
1726
3203
  versionId: state2.versionId,
1727
3204
  sessionId: state2.sessionId,
1728
3205
  ready: state2.ready,
@@ -1757,10 +3234,10 @@ var init_taskSessions = __esm({
1757
3234
  sessions;
1758
3235
  worlds;
1759
3236
  hash;
1760
- /** This alias's `{slug, ref}` as recorded at open/attach — the world a
1761
- * `TaskRun` filing needs to name, without exposing the whole map. */
3237
+ /** This alias's world as recorded at open/attach — what a `TaskRun`
3238
+ * filing needs to name, without exposing the whole map. */
1762
3239
  worldRef(alias) {
1763
- return this.worlds[alias] ?? { slug: "", ref: null };
3240
+ return this.worlds[alias] ?? { slug: "", ref: null, private: null };
1764
3241
  }
1765
3242
  /** The aliases, in the spec's order. */
1766
3243
  get aliases() {
@@ -2124,7 +3601,7 @@ var init_users = __esm({
2124
3601
  });
2125
3602
 
2126
3603
  // src/tracing/identity.ts
2127
- import { AsyncLocalStorage } from "async_hooks";
3604
+ import { AsyncLocalStorage as AsyncLocalStorage2 } from "async_hooks";
2128
3605
  import { isSpanContextValid, trace } from "@opentelemetry/api";
2129
3606
  function resolveUserId() {
2130
3607
  const contextual = currentUserStorage.getStore();
@@ -2138,7 +3615,7 @@ var init_identity = __esm({
2138
3615
  "use strict";
2139
3616
  init_users();
2140
3617
  USER_ID_ATTRIBUTE = "gateway.user.id";
2141
- currentUserStorage = new AsyncLocalStorage();
3618
+ currentUserStorage = new AsyncLocalStorage2();
2142
3619
  IdentitySpanProcessor = class {
2143
3620
  onStart(span, _parentContext) {
2144
3621
  const userId = resolveUserId();
@@ -2156,43 +3633,224 @@ var init_identity = __esm({
2156
3633
  }
2157
3634
  });
2158
3635
 
2159
- // src/tracing/session.ts
2160
- var session_exports2 = {};
2161
- __export(session_exports2, {
2162
- SESSION_ID_ATTRIBUTE: () => SESSION_ID_ATTRIBUTE,
2163
- SessionSpanProcessor: () => SessionSpanProcessor,
2164
- getAmbientSessionId: () => getAmbientSessionId,
2165
- withSession: () => withSession
2166
- });
2167
- import { AsyncLocalStorage as AsyncLocalStorage2 } from "async_hooks";
2168
- function getAmbientSessionId() {
2169
- return currentSessionStorage.getStore();
3636
+ // src/tracing/secrets.ts
3637
+ function jsonOrUndefined(text2) {
3638
+ let parsed;
3639
+ try {
3640
+ parsed = JSON.parse(text2);
3641
+ } catch {
3642
+ return void 0;
3643
+ }
3644
+ if (typeof parsed === "string") return parsed;
3645
+ return parsed !== null && typeof parsed === "object" ? parsed : void 0;
2170
3646
  }
2171
- function withSession(sessionId, fn) {
2172
- return new Promise((resolve7, reject) => {
2173
- currentSessionStorage.run(sessionId, () => {
2174
- Promise.resolve().then(fn).then(resolve7, reject);
2175
- });
3647
+ function encodings(value) {
3648
+ return [value, percentEncoded(value), JSON.stringify(value).slice(1, -1)];
3649
+ }
3650
+ function percentEncoded(value) {
3651
+ try {
3652
+ return encodeURIComponent(value);
3653
+ } catch {
3654
+ return value;
3655
+ }
3656
+ }
3657
+ function union(sets) {
3658
+ return new Set(sets.flatMap((set) => [...set]));
3659
+ }
3660
+ function leaves(value) {
3661
+ if (typeof value === "string") {
3662
+ return [...value].length >= MIN_SECRET_LENGTH ? /* @__PURE__ */ new Set([value]) : /* @__PURE__ */ new Set();
3663
+ }
3664
+ if (Array.isArray(value)) return union(value.map(leaves));
3665
+ if (value === null || typeof value !== "object") return /* @__PURE__ */ new Set();
3666
+ return union(Object.values(value).map(leaves));
3667
+ }
3668
+ function sameAttributes(before, after) {
3669
+ const keys = Object.keys(before);
3670
+ if (keys.length !== Object.keys(after).length) return false;
3671
+ return keys.every(
3672
+ (key) => before[key] === after[key] || sameArray(before[key], after[key])
3673
+ );
3674
+ }
3675
+ function sameArray(before, after) {
3676
+ if (!Array.isArray(before) || !Array.isArray(after)) return false;
3677
+ return before.length === after.length && before.every((item, i) => item === after[i]);
3678
+ }
3679
+ function scrubbedRead(reads, property) {
3680
+ return typeof property === "string" && property in reads ? reads[property] : void 0;
3681
+ }
3682
+ function viewOf(span, reads) {
3683
+ const view = new Proxy(span, {
3684
+ get(target, property) {
3685
+ const read = scrubbedRead(reads, property);
3686
+ if (read) return read();
3687
+ const value = Reflect.get(target, property, target);
3688
+ if (typeof value !== "function") return value;
3689
+ return (...args) => {
3690
+ const result = value.apply(target, args);
3691
+ return result === target ? view : result;
3692
+ };
3693
+ },
3694
+ getOwnPropertyDescriptor(target, property) {
3695
+ const descriptor = Reflect.getOwnPropertyDescriptor(target, property);
3696
+ const read = scrubbedRead(reads, property);
3697
+ if (!read || !descriptor || !("value" in descriptor)) return descriptor;
3698
+ return { ...descriptor, value: read() };
3699
+ }
2176
3700
  });
3701
+ return view;
2177
3702
  }
2178
- var SESSION_ID_ATTRIBUTE, currentSessionStorage, SessionSpanProcessor;
2179
- var init_session2 = __esm({
2180
- "src/tracing/session.ts"() {
3703
+ var SECRET_KEYS, REDACTED2, MIN_SECRET_LENGTH, SpanSecrets, SPAN_SECRETS, SecretRedactingSpanProcessor;
3704
+ var init_secrets = __esm({
3705
+ "src/tracing/secrets.ts"() {
2181
3706
  "use strict";
2182
- SESSION_ID_ATTRIBUTE = "gateway.session.id";
2183
- currentSessionStorage = new AsyncLocalStorage2();
2184
- SessionSpanProcessor = class {
2185
- onStart(span, _parentContext) {
2186
- const sessionId = getAmbientSessionId();
2187
- if (sessionId) {
2188
- span.setAttribute(SESSION_ID_ATTRIBUTE, sessionId);
3707
+ SECRET_KEYS = /* @__PURE__ */ new Set([
3708
+ "authorization_token",
3709
+ "authorizationToken"
3710
+ ]);
3711
+ REDACTED2 = "[redacted: holds a credential]";
3712
+ MIN_SECRET_LENGTH = 8;
3713
+ SpanSecrets = class {
3714
+ constructor(keys = SECRET_KEYS) {
3715
+ this.keys = keys;
3716
+ }
3717
+ keys;
3718
+ isSecret(key) {
3719
+ return this.keys.has(key);
3720
+ }
3721
+ drops(attribute) {
3722
+ return this.mentions(attribute);
3723
+ }
3724
+ strip(value) {
3725
+ if (typeof value === "string") return this.stripNested(value);
3726
+ if (Array.isArray(value)) return value.map((item) => this.strip(item));
3727
+ if (value === null || typeof value !== "object") return value;
3728
+ return Object.fromEntries(
3729
+ Object.entries(value).filter(([key]) => !this.isSecret(key)).map(([key, item]) => [key, this.strip(item)])
3730
+ );
3731
+ }
3732
+ scrubAttribute(value) {
3733
+ try {
3734
+ return this.scrubbedValue(value);
3735
+ } catch {
3736
+ return Array.isArray(value) ? [REDACTED2] : REDACTED2;
2189
3737
  }
2190
3738
  }
2191
- onEnd(_span) {
3739
+ scrubbedValue(value) {
3740
+ if (typeof value === "string") return this.scrubbedText(value);
3741
+ if (!Array.isArray(value)) return value;
3742
+ const results = value.map(
3743
+ (item) => typeof item === "string" ? this.cleaned(item) : { text: item, removed: /* @__PURE__ */ new Set() }
3744
+ );
3745
+ const removed = new Set(results.flatMap((r) => [...r.removed]));
3746
+ const scrubbed = results.map((r) => r.text);
3747
+ const withheld = scrubbed.some(
3748
+ (item) => typeof item === "string" && this.carries(item, removed)
3749
+ );
3750
+ return withheld ? [REDACTED2] : scrubbed;
2192
3751
  }
2193
- async shutdown() {
3752
+ scrubAttributes(attributes) {
3753
+ return Object.fromEntries(
3754
+ Object.entries(attributes).filter(([key]) => !this.drops(key)).map(([key, value]) => [key, this.scrubAttribute(value)])
3755
+ );
2194
3756
  }
2195
- async forceFlush() {
3757
+ mentions(text2) {
3758
+ return [...this.keys].some((key) => text2.includes(key));
3759
+ }
3760
+ scrubbedText(text2) {
3761
+ const { text: cleaned, removed } = this.cleaned(text2);
3762
+ return this.carries(cleaned, removed) ? REDACTED2 : cleaned;
3763
+ }
3764
+ cleaned(text2) {
3765
+ if (!this.mentions(text2)) return { text: text2, removed: /* @__PURE__ */ new Set() };
3766
+ const parsed = jsonOrUndefined(text2);
3767
+ if (parsed === void 0) return { text: REDACTED2, removed: /* @__PURE__ */ new Set() };
3768
+ return {
3769
+ text: JSON.stringify(this.strip(parsed)),
3770
+ removed: this.removed(parsed)
3771
+ };
3772
+ }
3773
+ carries(text2, removed) {
3774
+ if (text2 === REDACTED2 || this.mentions(text2)) return true;
3775
+ return [...removed].some(
3776
+ (value) => encodings(value).some((form) => text2.includes(form))
3777
+ );
3778
+ }
3779
+ removed(value) {
3780
+ if (typeof value === "string") {
3781
+ const nested = this.mentions(value) ? jsonOrUndefined(value) : void 0;
3782
+ return nested === void 0 ? /* @__PURE__ */ new Set() : this.removed(nested);
3783
+ }
3784
+ if (Array.isArray(value)) return union(value.map((v) => this.removed(v)));
3785
+ if (value === null || typeof value !== "object") return /* @__PURE__ */ new Set();
3786
+ return union(
3787
+ Object.entries(value).map(
3788
+ ([key, item]) => this.isSecret(key) ? leaves(item) : this.removed(item)
3789
+ )
3790
+ );
3791
+ }
3792
+ stripNested(text2) {
3793
+ if (!this.mentions(text2)) return text2;
3794
+ const parsed = jsonOrUndefined(text2);
3795
+ if (parsed === void 0) return text2;
3796
+ return JSON.stringify(this.strip(parsed));
3797
+ }
3798
+ };
3799
+ SPAN_SECRETS = new SpanSecrets();
3800
+ SecretRedactingSpanProcessor = class {
3801
+ constructor(inner, secrets = SPAN_SECRETS) {
3802
+ this.inner = inner;
3803
+ this.secrets = secrets;
3804
+ }
3805
+ inner;
3806
+ secrets;
3807
+ views = /* @__PURE__ */ new WeakMap();
3808
+ onStart(span, parentContext) {
3809
+ this.inner.onStart(this.viewFor(span), parentContext);
3810
+ }
3811
+ onEnd(span) {
3812
+ const view = this.viewFor(span);
3813
+ try {
3814
+ void [view.attributes, view.events, view.status];
3815
+ } catch (error) {
3816
+ console.warn(
3817
+ `[gatewaysdk.tracing] Dropped span "${span.name}": could not redact it: ${error?.name}`
3818
+ );
3819
+ return;
3820
+ }
3821
+ this.inner.onEnd(view);
3822
+ }
3823
+ viewFor(span) {
3824
+ const known = this.views.get(span);
3825
+ if (known) return known;
3826
+ const view = viewOf(span, {
3827
+ attributes: () => this.scrubbedAttributes(span.attributes),
3828
+ events: () => span.events.map((event) => this.scrubbedEvent(event)),
3829
+ status: () => this.scrubbedStatus(span.status)
3830
+ });
3831
+ this.views.set(span, view);
3832
+ return view;
3833
+ }
3834
+ forceFlush() {
3835
+ return this.inner.forceFlush();
3836
+ }
3837
+ shutdown() {
3838
+ return this.inner.shutdown();
3839
+ }
3840
+ scrubbedAttributes(attributes) {
3841
+ const clean = this.secrets.scrubAttributes(attributes);
3842
+ return sameAttributes(attributes, clean) ? attributes : clean;
3843
+ }
3844
+ scrubbedStatus(status) {
3845
+ if (!status.message) return status;
3846
+ const message = this.secrets.scrubAttribute(status.message);
3847
+ return message === status.message ? status : { ...status, message };
3848
+ }
3849
+ scrubbedEvent(event) {
3850
+ if (!event.attributes) return event;
3851
+ const attributes = this.scrubbedAttributes(event.attributes);
3852
+ if (attributes === event.attributes) return event;
3853
+ return { ...event, attributes };
2196
3854
  }
2197
3855
  };
2198
3856
  }
@@ -2419,7 +4077,7 @@ var require_package = __commonJS({
2419
4077
  "package.json"(exports, module) {
2420
4078
  module.exports = {
2421
4079
  name: "@withgateway/sdk",
2422
- version: "0.2.8",
4080
+ version: "0.3.0",
2423
4081
  description: "Gateway SDK for TypeScript - A/B experiments, tracing, and observability",
2424
4082
  main: "./dist/index.js",
2425
4083
  module: "./dist/index.mjs",
@@ -2619,7 +4277,7 @@ var require_package = __commonJS({
2619
4277
  });
2620
4278
 
2621
4279
  // src/build/index.ts
2622
- import { createHash } from "crypto";
4280
+ import { createHash as createHash2 } from "crypto";
2623
4281
  function canonicalJson(value) {
2624
4282
  if (value === null || typeof value !== "object") {
2625
4283
  return JSON.stringify(value);
@@ -2631,7 +4289,7 @@ function canonicalJson(value) {
2631
4289
  return `{${entries.map(([k, v]) => `${JSON.stringify(k)}:${canonicalJson(v)}`).join(",")}}`;
2632
4290
  }
2633
4291
  function sha256(text2) {
2634
- return `sha256:${createHash("sha256").update(text2).digest("hex")}`;
4292
+ return `sha256:${createHash2("sha256").update(text2).digest("hex")}`;
2635
4293
  }
2636
4294
  function getRegisteredTools() {
2637
4295
  return [...registeredTools.values()].sort(
@@ -2939,7 +4597,7 @@ function buildProvider(config, logFn) {
2939
4597
  const spanProcessors = [];
2940
4598
  if (config.customSpanProcessors) {
2941
4599
  for (const sp of config.customSpanProcessors) {
2942
- spanProcessors.push(sp);
4600
+ spanProcessors.push(new SecretRedactingSpanProcessor(sp));
2943
4601
  logFn(
2944
4602
  "Added custom span processor: %s",
2945
4603
  sp.constructor?.name ?? "unknown"
@@ -2958,7 +4616,11 @@ function buildProvider(config, logFn) {
2958
4616
  if (config.batch?.maxExportBatchSize) {
2959
4617
  batchConfig.maxExportBatchSize = config.batch.maxExportBatchSize;
2960
4618
  }
2961
- spanProcessors.push(new BatchSpanProcessor(exporter, batchConfig));
4619
+ spanProcessors.push(
4620
+ new SecretRedactingSpanProcessor(
4621
+ new BatchSpanProcessor(exporter, batchConfig)
4622
+ )
4623
+ );
2962
4624
  let provider = new NodeTracerProvider({
2963
4625
  resource: createResource(resourceAttrs)
2964
4626
  });
@@ -3096,7 +4758,8 @@ var init_init = __esm({
3096
4758
  "src/tracing/init.ts"() {
3097
4759
  "use strict";
3098
4760
  init_identity();
3099
- init_session2();
4761
+ init_secrets();
4762
+ init_session();
3100
4763
  init_scores();
3101
4764
  init_build();
3102
4765
  ENV_VARS = {
@@ -3252,7 +4915,7 @@ async function runTask(ref, agent, opts) {
3252
4915
  let extra = {};
3253
4916
  try {
3254
4917
  const invoke = () => agent(taskRun);
3255
- const result = traced ? await (await Promise.resolve().then(() => (init_session2(), session_exports2))).withSession(runId, invoke) : await invoke();
4918
+ const result = traced ? await (await Promise.resolve().then(() => (init_session(), session_exports))).withSession(runId, invoke) : await invoke();
3256
4919
  ({ report, extra } = reportFromResult(result));
3257
4920
  } catch (error) {
3258
4921
  const message = (error instanceof Error ? error.message : String(error)) || "Unknown error";
@@ -3325,7 +4988,7 @@ var init_taskRun = __esm({
3325
4988
  "use strict";
3326
4989
  init_browser();
3327
4990
  init_evals();
3328
- init_session();
4991
+ init_session2();
3329
4992
  init_taskSessions();
3330
4993
  TaskRun = class {
3331
4994
  constructor(runId, instruction, model, sessions, manifest) {
@@ -3634,7 +5297,7 @@ var init_checkoutTarget = __esm({
3634
5297
  });
3635
5298
 
3636
5299
  // src/worlds/worldDir.ts
3637
- import { createHash as createHash2 } from "crypto";
5300
+ import { createHash as createHash3 } from "crypto";
3638
5301
  import * as fs3 from "fs";
3639
5302
  import * as path3 from "path";
3640
5303
  var WORLD_MANIFEST, API_BUNDLE_MANIFEST, BUNDLED_WORLD_PREFIX, CONNECTOR_SPEC, PYPROJECT, BENCHMARK_CONFIG, WORLD_SCHEMA_MARKERS, WORLD_ROOT_MARKERS, BROAD_ROOT_MARKERS, SKIPPED_DIRS, V1_DEP, V1_IMPORT, V1_TASKSET, HARBOR_TASK, skippedDir, byCodePoint, WorldDir;
@@ -3744,7 +5407,7 @@ var init_worldDir = __esm({
3744
5407
  * sorted order: the version's identity, byte-compatible with
3745
5408
  * `_archive.compute_content_hash` and Prime Intellect. */
3746
5409
  get contentHash() {
3747
- const hasher = createHash2("sha256");
5410
+ const hasher = createHash3("sha256");
3748
5411
  for (const rel of this.archivePaths) {
3749
5412
  hasher.update(Buffer.from(`file:${rel}`, "utf-8"));
3750
5413
  hasher.update(fs3.readFileSync(path3.join(this.dir, rel)));
@@ -3940,7 +5603,7 @@ __export(hub_exports, {
3940
5603
  snapshotTreeHashes: () => snapshotTreeHashes,
3941
5604
  writeLocalMeta: () => writeLocalMeta
3942
5605
  });
3943
- import { createHash as createHash3 } from "crypto";
5606
+ import { createHash as createHash4 } from "crypto";
3944
5607
  import { gzipSync } from "zlib";
3945
5608
  import * as fs5 from "fs";
3946
5609
  import * as path5 from "path";
@@ -4052,7 +5715,7 @@ function writeLocalMeta(dir, meta) {
4052
5715
  function snapshotTreeHashes(dir) {
4053
5716
  const out = {};
4054
5717
  for (const relPath of collectArchiveRelPaths(dir)) {
4055
- out[relPath] = createHash3("sha256").update(fs5.readFileSync(path5.join(dir, relPath))).digest("hex");
5718
+ out[relPath] = createHash4("sha256").update(fs5.readFileSync(path5.join(dir, relPath))).digest("hex");
4056
5719
  }
4057
5720
  return out;
4058
5721
  }
@@ -4098,7 +5761,7 @@ function buildFileManifest(dir) {
4098
5761
  path: relPath,
4099
5762
  isDirectory: false,
4100
5763
  size: payload.length,
4101
- sha256: createHash3("sha256").update(payload).digest("hex")
5764
+ sha256: createHash4("sha256").update(payload).digest("hex")
4102
5765
  };
4103
5766
  });
4104
5767
  }
@@ -4323,7 +5986,7 @@ var init_hub = __esm({
4323
5986
  tracked;
4324
5987
  declared;
4325
5988
  };
4326
- sha256b64 = (data) => createHash3("sha256").update(data).digest("base64");
5989
+ sha256b64 = (data) => createHash4("sha256").update(data).digest("base64");
4327
5990
  DetachedPushError = class extends Error {
4328
5991
  constructor(dir, tag) {
4329
5992
  super(
@@ -4524,6 +6187,34 @@ function parseSlugRef(slugRef) {
4524
6187
  if (at === -1) return { slug: slugRef };
4525
6188
  return { slug: slugRef.slice(0, at), ref: slugRef.slice(at + 1) };
4526
6189
  }
6190
+ function rebaseConflicts(error) {
6191
+ if (!(error instanceof ApiError) || error.status !== 409) return null;
6192
+ let body;
6193
+ try {
6194
+ body = JSON.parse(error.text);
6195
+ } catch {
6196
+ return null;
6197
+ }
6198
+ const conflicts = body?.conflicts;
6199
+ if (!Array.isArray(conflicts)) return null;
6200
+ return conflicts.filter(isConflictPath).map(({ path: path12, reason }) => ({ path: path12, reason }));
6201
+ }
6202
+ function isConflictPath(value) {
6203
+ const entry = value;
6204
+ return typeof entry?.path === "string" && typeof entry.reason === "string";
6205
+ }
6206
+ function uncommittedPaths(error) {
6207
+ if (!(error instanceof ApiError) || error.status !== 409 || error.code !== "sandbox_uncommitted") return null;
6208
+ let body;
6209
+ try {
6210
+ body = JSON.parse(error.text);
6211
+ } catch {
6212
+ return null;
6213
+ }
6214
+ const uncommitted = body?.uncommitted;
6215
+ if (!Array.isArray(uncommitted)) return null;
6216
+ return uncommitted.filter((p) => typeof p === "string");
6217
+ }
4527
6218
  function listQuery(filter) {
4528
6219
  const params = new URLSearchParams();
4529
6220
  if (filter.status) params.set("status", filter.status);
@@ -4532,18 +6223,25 @@ function listQuery(filter) {
4532
6223
  const qs = params.toString();
4533
6224
  return qs ? `?${qs}` : "";
4534
6225
  }
4535
- var isSandboxImportPending, sid, WorldSandboxClient;
6226
+ var isSandboxImportPending, sid, SANDBOXES, SANDBOX_REQUEST_TIMEOUT_MS, WorldSandboxClient;
4536
6227
  var init_sandbox = __esm({
4537
6228
  "src/worlds/sandbox.ts"() {
4538
6229
  "use strict";
4539
6230
  init_worlds();
4540
6231
  isSandboxImportPending = (answer) => !("versionId" in answer);
4541
6232
  sid = encodeURIComponent;
6233
+ SANDBOXES = "/api/public/benchmark-containers/sandboxes";
6234
+ SANDBOX_REQUEST_TIMEOUT_MS = 66e4;
4542
6235
  WorldSandboxClient = class {
4543
6236
  constructor(options = {}) {
4544
6237
  this.options = options;
4545
6238
  }
4546
6239
  options;
6240
+ request(method, path12, body) {
6241
+ return apiRequest(this.options, method, path12, body, {
6242
+ timeoutMs: SANDBOX_REQUEST_TIMEOUT_MS
6243
+ });
6244
+ }
4547
6245
  /**
4548
6246
  * `{ slug, ref? }` opens a READY version; `{ new, from }` opens a sandbox on
4549
6247
  * a world that does not exist yet (409 `world_exists` if the slug is taken,
@@ -4551,42 +6249,39 @@ var init_sandbox = __esm({
4551
6249
  * creates the world on `main`.
4552
6250
  */
4553
6251
  open(target) {
4554
- return apiRequest(this.options, "POST", "/api/public/benchmark-containers/sandboxes", target);
6252
+ return this.request("POST", `${SANDBOXES}`, target);
4555
6253
  }
4556
6254
  status(sandboxId) {
4557
- return apiRequest(this.options, "GET", `/api/public/benchmark-containers/sandboxes/${sid(sandboxId)}`);
6255
+ return this.request("GET", `${SANDBOXES}/${sid(sandboxId)}`);
4558
6256
  }
4559
6257
  /** The project's sandboxes, newest first — how an agent finds one it left open. */
4560
6258
  async list(filter = {}) {
4561
- const res = await apiRequest(
4562
- this.options,
4563
- "GET",
4564
- `/api/public/benchmark-containers/sandboxes${listQuery(filter)}`
4565
- );
6259
+ const res = await this.request("GET", `${SANDBOXES}${listQuery(filter)}`);
4566
6260
  return res.sandboxes;
4567
6261
  }
4568
6262
  async read(sandboxId, filePath) {
4569
- const res = await apiRequest(
4570
- this.options,
6263
+ const res = await this.request(
4571
6264
  "GET",
4572
- `/api/public/benchmark-containers/sandboxes/${sid(sandboxId)}/file?path=${encodeURIComponent(filePath)}`
6265
+ `${SANDBOXES}/${sid(sandboxId)}/file?path=${encodeURIComponent(filePath)}`
4573
6266
  );
4574
6267
  return { path: res.path, size: res.size, bytes: Buffer.from(res.contentBase64, "base64") };
4575
6268
  }
4576
6269
  write(sandboxId, filePath, bytes) {
4577
- return apiRequest(this.options, "PUT", `/api/public/benchmark-containers/sandboxes/${sid(sandboxId)}/file`, {
6270
+ return this.request("PUT", `${SANDBOXES}/${sid(sandboxId)}/file`, {
4578
6271
  path: filePath,
4579
6272
  contentBase64: bytes.toString("base64")
4580
6273
  });
4581
6274
  }
4582
6275
  exec(sandboxId, input) {
4583
- return apiRequest(this.options, "POST", `/api/public/benchmark-containers/sandboxes/${sid(sandboxId)}/exec`, input);
6276
+ return this.request("POST", `${SANDBOXES}/${sid(sandboxId)}/exec`, input);
4584
6277
  }
4585
6278
  check(sandboxId) {
4586
- return apiRequest(this.options, "POST", `/api/public/benchmark-containers/sandboxes/${sid(sandboxId)}/check`, {});
6279
+ return this.request("POST", `${SANDBOXES}/${sid(sandboxId)}/check`, {});
4587
6280
  }
6281
+ /** With `rebase`, a moved base is replayed onto; a 409 then names the conflicting paths (`rebaseConflicts`). */
4588
6282
  commit(sandboxId, input) {
4589
- return apiRequest(this.options, "POST", `/api/public/benchmark-containers/sandboxes/${sid(sandboxId)}/commit`, input);
6283
+ const { rebase, ...rest } = input;
6284
+ return this.request("POST", `${SANDBOXES}/${sid(sandboxId)}/commit`, rebase ? { ...rest, rebase: true } : rest);
4590
6285
  }
4591
6286
  /**
4592
6287
  * A rows file already in the sandbox tree into the PLATFORM world the
@@ -4595,10 +6290,11 @@ var init_sandbox = __esm({
4595
6290
  * tree and never carries data.
4596
6291
  */
4597
6292
  importData(sandboxId, input) {
4598
- return apiRequest(this.options, "POST", `/api/public/benchmark-containers/sandboxes/${sid(sandboxId)}/import`, input);
6293
+ return this.request("POST", `${SANDBOXES}/${sid(sandboxId)}/import`, input);
4599
6294
  }
4600
- close(sandboxId) {
4601
- return apiRequest(this.options, "DELETE", `/api/public/benchmark-containers/sandboxes/${sid(sandboxId)}`);
6295
+ /** Uncommitted work is a 409 (`uncommittedPaths`) unless `force` discards it. */
6296
+ close(sandboxId, opts = {}) {
6297
+ return this.request("DELETE", `${SANDBOXES}/${sid(sandboxId)}`, opts.force ? { force: true } : void 0);
4602
6298
  }
4603
6299
  };
4604
6300
  }
@@ -4917,7 +6613,7 @@ var init_json = __esm({
4917
6613
  });
4918
6614
 
4919
6615
  // src/worlds/transforms.ts
4920
- import { createHash as createHash4 } from "crypto";
6616
+ import { createHash as createHash5 } from "crypto";
4921
6617
  function parseTransform(name) {
4922
6618
  const simple = Object.prototype.hasOwnProperty.call(SIMPLE, name) ? SIMPLE[name] : void 0;
4923
6619
  if (simple) return simple;
@@ -4955,7 +6651,7 @@ var init_transforms = __esm({
4955
6651
  return at === -1 ? "" : value.slice(at + 1).toLowerCase();
4956
6652
  };
4957
6653
  stripPrefix = (prefix) => (value) => value.startsWith(prefix) ? value.slice(prefix.length) : value;
4958
- hex = (algorithm, value) => createHash4(algorithm).update(value, "utf8").digest("hex");
6654
+ hex = (algorithm, value) => createHash5(algorithm).update(value, "utf8").digest("hex");
4959
6655
  SIMPLE = {
4960
6656
  lower: (value) => value.toLowerCase(),
4961
6657
  upper: (value) => value.toUpperCase(),
@@ -4979,7 +6675,7 @@ var init_transforms = __esm({
4979
6675
  });
4980
6676
 
4981
6677
  // src/worlds/redaction.ts
4982
- import { createHash as createHash5 } from "crypto";
6678
+ import { createHash as createHash6 } from "crypto";
4983
6679
  function pyText(value) {
4984
6680
  if (typeof value === "string") return value;
4985
6681
  if (Number.isInteger(value)) return String(value);
@@ -4988,7 +6684,7 @@ function pyText(value) {
4988
6684
  return pyFloatRepr(value);
4989
6685
  }
4990
6686
  function hashForm(slug, plaintext) {
4991
- return "sha256:" + createHash5("sha256").update(`${slug}:${pyText(plaintext)}`, "utf8").digest("hex");
6687
+ return "sha256:" + createHash6("sha256").update(`${slug}:${pyText(plaintext)}`, "utf8").digest("hex");
4992
6688
  }
4993
6689
  function preserveForm(slug, plaintext) {
4994
6690
  const kind = typeof plaintext === "string" ? "str" : isInt(plaintext) ? "int" : "float";
@@ -4997,12 +6693,12 @@ function preserveForm(slug, plaintext) {
4997
6693
  }
4998
6694
  function shapeText(slug, text2, kind) {
4999
6695
  const seed = Buffer.from(`${slug}:${text2}`, "utf8");
5000
- let digest = createHash5("sha256").update(seed).digest();
6696
+ let digest = createHash6("sha256").update(seed).digest();
5001
6697
  let cursor = 0;
5002
6698
  const out = [];
5003
6699
  for (const char of text2) {
5004
6700
  if (cursor === digest.length) {
5005
- digest = createHash5("sha256").update(Buffer.concat([digest, seed])).digest();
6701
+ digest = createHash6("sha256").update(Buffer.concat([digest, seed])).digest();
5006
6702
  cursor = 0;
5007
6703
  }
5008
6704
  const byte = digest[cursor];
@@ -5130,48 +6826,19 @@ var init_router = __esm({
5130
6826
  import * as fs6 from "fs";
5131
6827
  import * as os from "os";
5132
6828
  import * as path6 from "path";
5133
- function transportDetail(error, timeoutMs) {
5134
- if (error instanceof Error && error.name === "AbortError") return `timed out after ${Math.round(timeoutMs / 1e3)}s`;
5135
- const cause = error instanceof Error && error.cause instanceof Error ? error.cause : void 0;
5136
- const code = cause && "code" in cause && typeof cause.code === "string" ? `${cause.code}: ` : "";
5137
- const message = cause?.message ?? (error instanceof Error ? error.message : String(error));
5138
- return `${code}${message}`;
5139
- }
5140
6829
  async function api(creds, method, route, body, init2 = {}) {
5141
- const controller = new AbortController();
5142
- const timeoutMs = init2.timeoutMs ?? 12e4;
5143
- const timer = setTimeout(() => controller.abort(), timeoutMs);
5144
- let res;
5145
- try {
5146
- res = await fetch(`${creds.host}${route}`, {
5147
- method,
5148
- headers: {
5149
- "content-type": "application/json",
5150
- accept: "application/json",
5151
- authorization: "Basic " + Buffer.from(`${creds.publicKey}:${creds.secretKey}`).toString("base64")
5152
- },
5153
- ...body === void 0 ? {} : { body: JSON.stringify(body) },
5154
- signal: controller.signal
5155
- });
5156
- } catch (error) {
5157
- clearTimeout(timer);
5158
- throw new UnreachableError(creds.host, method, route, transportDetail(error, timeoutMs));
5159
- }
5160
- try {
5161
- const text2 = await res.text();
5162
- if (!res.ok) throw new ApiError(res.status, method, route, text2);
5163
- return text2 ? JSON.parse(text2) : {};
5164
- } finally {
5165
- clearTimeout(timer);
5166
- }
6830
+ const reply = await new PlatformTransport(creds).send(method, route, body, init2);
6831
+ if (!reply.ok) throw new ApiError2(reply.status, method, route, reply.text);
6832
+ return reply.text ? JSON.parse(reply.text) : {};
5167
6833
  }
5168
- var ApiError, UnreachableError;
6834
+ var ApiError2;
5169
6835
  var init_config = __esm({
5170
6836
  "src/cli/config.ts"() {
5171
6837
  "use strict";
5172
6838
  init_router();
5173
6839
  init_worlds();
5174
- ApiError = class extends CliError {
6840
+ init_transport();
6841
+ ApiError2 = class extends CliError {
5175
6842
  constructor(status, method, route, text2) {
5176
6843
  const body = parseErrorBody(text2);
5177
6844
  super(`${method} ${route} -> ${status}: ${body.detail}`, 1);
@@ -5187,19 +6854,6 @@ var init_config = __esm({
5187
6854
  text;
5188
6855
  code;
5189
6856
  };
5190
- UnreachableError = class extends CliError {
5191
- constructor(host, method, route, detail) {
5192
- super(`${method} ${route}: no answer from ${host} (${detail}). Check the host and the network, then retry.`, 1);
5193
- this.host = host;
5194
- this.method = method;
5195
- this.route = route;
5196
- this.detail = detail;
5197
- }
5198
- host;
5199
- method;
5200
- route;
5201
- detail;
5202
- };
5203
6857
  }
5204
6858
  });
5205
6859
 
@@ -5378,7 +7032,7 @@ var init_local = __esm({
5378
7032
  "use strict";
5379
7033
  init_router();
5380
7034
  init_config();
5381
- MIN_PYTHON = [3, 11];
7035
+ MIN_PYTHON = [3, 12];
5382
7036
  DIAGNOSTIC_TAIL = 600;
5383
7037
  BRIDGE_BOOTSTRAP = `import sys,runpy,types,os
5384
7038
  root=sys.argv[1]
@@ -5390,7 +7044,6 @@ runpy.run_module('gatewaysdk.environment.schema.platform',run_name='__main__')`;
5390
7044
  PYTHON_CANDIDATES = [
5391
7045
  "python3.13",
5392
7046
  "python3.12",
5393
- "python3.11",
5394
7047
  "python3",
5395
7048
  "python"
5396
7049
  ];
@@ -5502,53 +7155,41 @@ function runsLocally(request) {
5502
7155
  async function runtime(creds, request, opts = {}) {
5503
7156
  const local = localRuntime();
5504
7157
  if (local && runsLocally(request)) {
5505
- const payload = await localBridge(request, local, opts);
5506
- const detail = detailFrom(payload);
5507
- if (detail) throw new BridgeRejected(detail);
5508
- return payload;
7158
+ const payload2 = await localBridge(request, local, opts);
7159
+ const detail2 = detailFrom(payload2);
7160
+ if (detail2) throw new BridgeRejected(detail2);
7161
+ return payload2;
5509
7162
  }
5510
7163
  if (!creds)
5511
7164
  throw new CliError(
5512
7165
  "This needs the schema runtime (the CLI bundles it) or platform credentials (`gateway auth login`). " + localRuntimeReason()
5513
7166
  );
5514
- const controller = new AbortController();
5515
- const timer = setTimeout(() => controller.abort(), opts.timeoutMs ?? 18e4);
5516
7167
  const route = "/api/public/worlds/runtime";
7168
+ const res = await new PlatformTransport(creds).send("POST", route, request, {
7169
+ timeoutMs: opts.timeoutMs ?? RUNTIME_TIMEOUT_MS
7170
+ });
7171
+ let payload = null;
5517
7172
  try {
5518
- const res = await fetch(`${creds.host}${route}`, {
5519
- method: "POST",
5520
- headers: {
5521
- "content-type": "application/json",
5522
- accept: "application/json",
5523
- authorization: "Basic " + Buffer.from(`${creds.publicKey}:${creds.secretKey}`).toString("base64")
5524
- },
5525
- body: JSON.stringify(request),
5526
- signal: controller.signal
5527
- });
5528
- const text2 = await res.text();
5529
- let payload = null;
5530
- try {
5531
- payload = text2 ? JSON.parse(text2) : {};
5532
- } catch {
5533
- payload = null;
5534
- }
5535
- const detail = detailFrom(payload);
5536
- if (detail) throw new BridgeRejected(detail);
5537
- if (!res.ok)
5538
- throw new CliError(`POST ${route} (${request.command}) -> ${res.status}: ${text2.slice(0, 600)}`, 1);
5539
- if (payload === null) throw new CliError(`POST ${route} (${request.command}) returned non-JSON`, 1);
5540
- return payload;
5541
- } finally {
5542
- clearTimeout(timer);
7173
+ payload = res.text ? JSON.parse(res.text) : {};
7174
+ } catch {
7175
+ payload = null;
5543
7176
  }
7177
+ const detail = detailFrom(payload);
7178
+ if (detail) throw new BridgeRejected(detail);
7179
+ if (!res.ok)
7180
+ throw new CliError(`POST ${route} (${request.command}) -> ${res.status}: ${res.text.slice(0, 600)}`, 1);
7181
+ if (payload === null) throw new CliError(`POST ${route} (${request.command}) returned non-JSON`, 1);
7182
+ return payload;
5544
7183
  }
5545
- var MAX_WORLD_FILES, SKIP_DIRS, BUILD_OUTPUT, BridgeRejected, YAML_NAME;
7184
+ var MAX_WORLD_FILES, RUNTIME_TIMEOUT_MS, SKIP_DIRS, BUILD_OUTPUT, BridgeRejected, YAML_NAME;
5546
7185
  var init_client = __esm({
5547
7186
  "src/cli/runtime/client.ts"() {
5548
7187
  "use strict";
5549
7188
  init_router();
5550
7189
  init_local();
7190
+ init_transport();
5551
7191
  MAX_WORLD_FILES = 2e3;
7192
+ RUNTIME_TIMEOUT_MS = 18e4;
5552
7193
  SKIP_DIRS = /* @__PURE__ */ new Set(["__pycache__", ".git", "node_modules", ".gateway"]);
5553
7194
  BUILD_OUTPUT = /(^|\/)state\.(sqlite|json)$/;
5554
7195
  BridgeRejected = class extends CliError {
@@ -5956,7 +7597,7 @@ if (fn) {
5956
7597
  });
5957
7598
 
5958
7599
  // src/cli/platform/worldData/batches.ts
5959
- import { createHash as createHash6 } from "crypto";
7600
+ import { createHash as createHash7 } from "crypto";
5960
7601
  import * as fs11 from "fs";
5961
7602
  function isSettled(status) {
5962
7603
  if (!TERMINAL_STATES.has(status.state)) return false;
@@ -5967,7 +7608,7 @@ function uploadHeadersFor(gz) {
5967
7608
  return {
5968
7609
  "content-type": "application/gzip",
5969
7610
  "content-length": String(gz.length),
5970
- "x-amz-checksum-sha256": createHash6("sha256").update(gz).digest("base64")
7611
+ "x-amz-checksum-sha256": createHash7("sha256").update(gz).digest("base64")
5971
7612
  };
5972
7613
  }
5973
7614
  async function forEachLimited(items, limit, fn) {
@@ -6170,7 +7811,7 @@ var init_batches = __esm({
6170
7811
  });
6171
7812
 
6172
7813
  // src/cli/platform/worldData/chunker.ts
6173
- import { createHash as createHash7 } from "crypto";
7814
+ import { createHash as createHash8 } from "crypto";
6174
7815
  import { deflateRawSync } from "zlib";
6175
7816
  function chunkLine(row, declared) {
6176
7817
  if (declared !== null) return dumps(row.row) + "\n";
@@ -6211,12 +7852,12 @@ function finishChunk(ordinal, raw, rows, entity, firstRow = 0) {
6211
7852
  const gz = gzipDeterministic(raw, { name: chunkName(ordinal) });
6212
7853
  return {
6213
7854
  ordinal,
6214
- digest: createHash7("sha256").update(gz).digest("hex"),
7855
+ digest: createHash8("sha256").update(gz).digest("hex"),
6215
7856
  bytes: gz.length,
6216
7857
  rows,
6217
7858
  entity,
6218
7859
  rawBytes: raw.length,
6219
- contentSha256: createHash7("sha256").update(raw).digest("hex"),
7860
+ contentSha256: createHash8("sha256").update(raw).digest("hex"),
6220
7861
  firstRow,
6221
7862
  gz
6222
7863
  };
@@ -6553,7 +8194,7 @@ var init_ingest = __esm({
6553
8194
  });
6554
8195
 
6555
8196
  // src/worlds/editSessions.ts
6556
- var WORLDS, WorldEditClient;
8197
+ var WORLDS, WorldEditClient, TASK_EDITS, TaskEditClient;
6557
8198
  var init_editSessions = __esm({
6558
8199
  "src/worlds/editSessions.ts"() {
6559
8200
  "use strict";
@@ -6585,6 +8226,22 @@ var init_editSessions = __esm({
6585
8226
  return apiRequest(this.options, "POST", `${WORLDS}/${encodeURIComponent(slug)}/edits/rollback`, input);
6586
8227
  }
6587
8228
  };
8229
+ TASK_EDITS = "/api/public/world-task-edits";
8230
+ TaskEditClient = class {
8231
+ constructor(options = {}) {
8232
+ this.options = options;
8233
+ }
8234
+ options;
8235
+ status(task) {
8236
+ return apiRequest(this.options, "POST", `${TASK_EDITS}/status`, { task });
8237
+ }
8238
+ close(task, input = {}) {
8239
+ return apiRequest(this.options, "POST", `${TASK_EDITS}/close`, { task, ...input });
8240
+ }
8241
+ rollback(task, input) {
8242
+ return apiRequest(this.options, "POST", `${TASK_EDITS}/rollback`, { task, ...input });
8243
+ }
8244
+ };
6588
8245
  }
6589
8246
  });
6590
8247
 
@@ -6680,7 +8337,11 @@ var init_dryRun = __esm({
6680
8337
  // src/worlds/index.ts
6681
8338
  var worlds_exports = {};
6682
8339
  __export(worlds_exports, {
6683
- ApiError: () => ApiError2,
8340
+ ACTION_NAMES: () => ACTION_NAMES,
8341
+ ActionTracer: () => ActionTracer,
8342
+ AnthropicComputer: () => AnthropicComputer,
8343
+ AnthropicComputer20251124: () => AnthropicComputer20251124,
8344
+ ApiError: () => ApiError,
6684
8345
  BROWSER_GONE_PATTERNS: () => BROWSER_GONE_PATTERNS,
6685
8346
  BROWSER_TIERS: () => BROWSER_TIERS,
6686
8347
  BrowserActionRecorder: () => BrowserActionRecorder,
@@ -6691,11 +8352,13 @@ __export(worlds_exports, {
6691
8352
  CALL_BODY_LIMIT_LABEL: () => CALL_BODY_LIMIT_LABEL,
6692
8353
  COMPUTER_USE_SPECS: () => COMPUTER_USE_SPECS,
6693
8354
  CheckoutProvenance: () => CheckoutProvenance,
8355
+ ComputerAction: () => ComputerAction,
6694
8356
  DEFAULT_BRANCH: () => DEFAULT_BRANCH,
6695
8357
  DEFAULT_VIEWPORT: () => DEFAULT_VIEWPORT,
6696
8358
  DRY_RUN_AGENT: () => DRY_RUN_AGENT,
6697
8359
  DRY_RUN_KIND: () => DRY_RUN_KIND,
6698
8360
  DetachedPushError: () => DetachedPushError,
8361
+ Display: () => Display,
6699
8362
  DryRunOutcome: () => DryRunOutcome,
6700
8363
  EVENT_BATCH_SIZE: () => EVENT_BATCH_SIZE,
6701
8364
  EVENT_FLUSH_INTERVAL_MS: () => EVENT_FLUSH_INTERVAL_MS,
@@ -6705,17 +8368,34 @@ __export(worlds_exports, {
6705
8368
  GatewayEvalsClient: () => GatewayEvalsClient,
6706
8369
  HostedDryRunClient: () => HostedDryRunClient,
6707
8370
  IDLE_WARNING_MINUTES: () => IDLE_WARNING_MINUTES,
8371
+ KEY_NAMES: () => KEY_NAMES,
8372
+ KeyChord: () => KeyChord,
8373
+ NOT_EXECUTED: () => NOT_EXECUTED,
6708
8374
  NO_GRADER_REASON: () => NO_GRADER_REASON,
8375
+ NativeComputer: () => NativeComputer,
8376
+ OpenAIComputer: () => OpenAIComputer,
8377
+ OpenAIPreviewComputer: () => OpenAIPreviewComputer,
8378
+ PLATFORM_TIMEOUT_DEFAULT_MS: () => PLATFORM_TIMEOUT_DEFAULT_MS,
8379
+ PLATFORM_TIMEOUT_ENV: () => PLATFORM_TIMEOUT_ENV,
8380
+ PendingSafetyChecks: () => PendingSafetyChecks,
8381
+ PlatformTransport: () => PlatformTransport,
6709
8382
  PushSlugConflict: () => PushSlugConflict,
6710
8383
  RECOVER_BUDGET_MS: () => RECOVER_BUDGET_MS,
8384
+ SANDBOX_REQUEST_TIMEOUT_MS: () => SANDBOX_REQUEST_TIMEOUT_MS,
8385
+ SECRET_KEY: () => SECRET_KEY,
6711
8386
  SESSION_STATES: () => SESSION_STATES,
8387
+ SPAN_PREFIX: () => SPAN_PREFIX,
6712
8388
  STATUS_WAIT_CAP_SECONDS: () => STATUS_WAIT_CAP_SECONDS,
6713
8389
  STRIP_PREFIX: () => STRIP_PREFIX,
6714
8390
  SURFACE_KINDS: () => SURFACE_KINDS,
8391
+ Screen: () => Screen,
6715
8392
  SecretScrubber: () => SecretScrubber,
6716
8393
  TRANSFORMS: () => TRANSFORMS,
8394
+ TaskEditClient: () => TaskEditClient,
6717
8395
  TaskRun: () => TaskRun,
6718
8396
  TaskSessions: () => TaskSessions,
8397
+ TransportCause: () => TransportCause,
8398
+ UnreachableError: () => UnreachableError,
6719
8399
  VERIFIER_REWARD_PREFIX: () => VERIFIER_REWARD_PREFIX,
6720
8400
  WHITESPACE: () => WHITESPACE,
6721
8401
  WorldBrowser: () => WorldBrowser,
@@ -6783,6 +8463,8 @@ __export(worlds_exports, {
6783
8463
  parseToolCallRecord: () => parseToolCallRecord,
6784
8464
  parseTransform: () => parseTransform,
6785
8465
  parseWorldTaskRefs: () => parseWorldTaskRefs,
8466
+ platformTimeoutMs: () => platformTimeoutMs,
8467
+ playwrightKey: () => playwrightKey,
6786
8468
  preserveForm: () => preserveForm,
6787
8469
  propose: () => propose,
6788
8470
  pull: () => pull,
@@ -6792,8 +8474,10 @@ __export(worlds_exports, {
6792
8474
  pyText: () => pyText,
6793
8475
  queryRows: () => queryRows,
6794
8476
  queryRowsSearch: () => queryRowsSearch,
8477
+ readField: () => readField,
6795
8478
  readLocalMeta: () => readLocalMeta,
6796
8479
  readToolCallRecords: () => readToolCallRecords,
8480
+ rebaseConflicts: () => rebaseConflicts,
6797
8481
  redactActionArgs: () => redactActionArgs,
6798
8482
  redactionOf: () => redactionOf,
6799
8483
  releaseConnection: () => releaseConnection,
@@ -6816,6 +8500,7 @@ __export(worlds_exports, {
6816
8500
  toolCallsFromObservations: () => toolCallsFromObservations,
6817
8501
  uiEntryUrl: () => uiEntryUrl,
6818
8502
  uiUrl: () => uiUrl,
8503
+ uncommittedPaths: () => uncommittedPaths,
6819
8504
  updateTask: () => updateTask,
6820
8505
  upsertRunConfig: () => upsertRunConfig,
6821
8506
  validateTask: () => validateTask,
@@ -6854,19 +8539,10 @@ function parseErrorBody(text2, limit = 600) {
6854
8539
  code: stableCode
6855
8540
  };
6856
8541
  }
6857
- async function apiRequest(options, method, path12, body) {
6858
- const { host, publicKey, secretKey } = resolveEnv(options);
6859
- const res = await fetch(`${host}${path12}`, {
6860
- method,
6861
- headers: {
6862
- "content-type": "application/json",
6863
- authorization: "Basic " + Buffer.from(`${publicKey}:${secretKey}`).toString("base64")
6864
- },
6865
- ...body === void 0 ? {} : { body: JSON.stringify(body) }
6866
- });
6867
- const text2 = await res.text();
6868
- if (!res.ok) throw new ApiError2(res.status, method, path12, text2);
6869
- return JSON.parse(text2);
8542
+ async function apiRequest(options, method, path12, body, init2 = {}) {
8543
+ const reply = await new PlatformTransport(resolveEnv(options)).send(method, path12, body, init2);
8544
+ if (!reply.ok) throw new ApiError(reply.status, method, path12, reply.text);
8545
+ return JSON.parse(reply.text);
6870
8546
  }
6871
8547
  async function setEnvSecret(slug, key, value, options = {}) {
6872
8548
  return apiRequest(
@@ -7042,10 +8718,12 @@ async function resolveWorld(slugRef, slug, ref, pin, options) {
7042
8718
  }
7043
8719
  return world;
7044
8720
  }
7045
- var ApiError2, WorldTask, WorldSet;
8721
+ var ApiError, WorldTask, WorldSet;
7046
8722
  var init_worlds = __esm({
7047
8723
  "src/worlds/index.ts"() {
7048
- init_session();
8724
+ init_transport();
8725
+ init_transport();
8726
+ init_session2();
7049
8727
  init_sessionList();
7050
8728
  init_sessionContract();
7051
8729
  init_taskRef();
@@ -7057,6 +8735,7 @@ var init_worlds = __esm({
7057
8735
  init_evals();
7058
8736
  init_browser();
7059
8737
  init_browserReconnect();
8738
+ init_nativeComputer();
7060
8739
  init_hub();
7061
8740
  init_validate();
7062
8741
  init_describe();
@@ -7068,15 +8747,17 @@ var init_worlds = __esm({
7068
8747
  init_sandbox();
7069
8748
  init_editSessions();
7070
8749
  init_dryRun();
7071
- ApiError2 = class extends Error {
7072
- constructor(status, method, path12, body) {
7073
- const parsed = parseErrorBody(body);
8750
+ ApiError = class extends Error {
8751
+ constructor(status, method, path12, text2) {
8752
+ const parsed = parseErrorBody(text2);
7074
8753
  super(`${method} ${path12} -> ${status}: ${parsed.detail}`);
7075
8754
  this.status = status;
8755
+ this.text = text2;
7076
8756
  this.name = "ApiError";
7077
8757
  this.code = parsed.code;
7078
8758
  }
7079
8759
  status;
8760
+ text;
7080
8761
  code;
7081
8762
  };
7082
8763
  WorldTask = class {
@@ -7121,7 +8802,7 @@ var init_worlds = __esm({
7121
8802
  * worlds/session.ts.
7122
8803
  */
7123
8804
  async open(task, opts = {}) {
7124
- const { openSession: openSession2 } = await Promise.resolve().then(() => (init_session(), session_exports));
8805
+ const { openSession: openSession2 } = await Promise.resolve().then(() => (init_session2(), session_exports2));
7125
8806
  return openSession2(this.slug, {
7126
8807
  task,
7127
8808
  versionId: this.version.versionId,
@@ -7155,7 +8836,11 @@ var init_worlds = __esm({
7155
8836
  });
7156
8837
  init_worlds();
7157
8838
  export {
7158
- ApiError2 as ApiError,
8839
+ ACTION_NAMES,
8840
+ ActionTracer,
8841
+ AnthropicComputer,
8842
+ AnthropicComputer20251124,
8843
+ ApiError,
7159
8844
  BROWSER_GONE_PATTERNS,
7160
8845
  BROWSER_TIERS,
7161
8846
  BrowserActionRecorder,
@@ -7166,11 +8851,13 @@ export {
7166
8851
  CALL_BODY_LIMIT_LABEL,
7167
8852
  COMPUTER_USE_SPECS,
7168
8853
  CheckoutProvenance,
8854
+ ComputerAction,
7169
8855
  DEFAULT_BRANCH,
7170
8856
  DEFAULT_VIEWPORT,
7171
8857
  DRY_RUN_AGENT,
7172
8858
  DRY_RUN_KIND,
7173
8859
  DetachedPushError,
8860
+ Display,
7174
8861
  DryRunOutcome,
7175
8862
  EVENT_BATCH_SIZE,
7176
8863
  EVENT_FLUSH_INTERVAL_MS,
@@ -7180,17 +8867,34 @@ export {
7180
8867
  GatewayEvalsClient,
7181
8868
  HostedDryRunClient,
7182
8869
  IDLE_WARNING_MINUTES,
8870
+ KEY_NAMES,
8871
+ KeyChord,
8872
+ NOT_EXECUTED,
7183
8873
  NO_GRADER_REASON,
8874
+ NativeComputer,
8875
+ OpenAIComputer,
8876
+ OpenAIPreviewComputer,
8877
+ PLATFORM_TIMEOUT_DEFAULT_MS,
8878
+ PLATFORM_TIMEOUT_ENV,
8879
+ PendingSafetyChecks,
8880
+ PlatformTransport,
7184
8881
  PushSlugConflict,
7185
8882
  RECOVER_BUDGET_MS,
8883
+ SANDBOX_REQUEST_TIMEOUT_MS,
8884
+ SECRET_KEY,
7186
8885
  SESSION_STATES,
8886
+ SPAN_PREFIX,
7187
8887
  STATUS_WAIT_CAP_SECONDS,
7188
8888
  STRIP_PREFIX,
7189
8889
  SURFACE_KINDS,
8890
+ Screen,
7190
8891
  SecretScrubber,
7191
8892
  TRANSFORMS,
8893
+ TaskEditClient,
7192
8894
  TaskRun,
7193
8895
  TaskSessions,
8896
+ TransportCause,
8897
+ UnreachableError,
7194
8898
  VERIFIER_REWARD_PREFIX,
7195
8899
  WHITESPACE,
7196
8900
  WorldBrowser,
@@ -7258,6 +8962,8 @@ export {
7258
8962
  parseToolCallRecord,
7259
8963
  parseTransform,
7260
8964
  parseWorldTaskRefs,
8965
+ platformTimeoutMs,
8966
+ playwrightKey,
7261
8967
  preserveForm,
7262
8968
  propose,
7263
8969
  pull,
@@ -7267,8 +8973,10 @@ export {
7267
8973
  pyText,
7268
8974
  queryRows,
7269
8975
  queryRowsSearch,
8976
+ readField,
7270
8977
  readLocalMeta,
7271
8978
  readToolCallRecords,
8979
+ rebaseConflicts,
7272
8980
  redactActionArgs,
7273
8981
  redactionOf,
7274
8982
  releaseConnection,
@@ -7291,6 +8999,7 @@ export {
7291
8999
  toolCallsFromObservations,
7292
9000
  uiEntryUrl,
7293
9001
  uiUrl,
9002
+ uncommittedPaths,
7294
9003
  updateTask,
7295
9004
  upsertRunConfig,
7296
9005
  validateTask,